Skip to content

bound vector deserialization total allocation in persistence - #134

Merged
kacy merged 1 commit into
mainfrom
security/persistence-hardening
Feb 14, 2026
Merged

bound vector deserialization total allocation in persistence#134
kacy merged 1 commit into
mainfrom
security/persistence-hardening

Conversation

@kacy

@kacy kacy commented Feb 14, 2026

Copy link
Copy Markdown
Owner

summary

addresses security audit finding #14: vector deserialization unbounded memory.

snapshot deserialization validates dim <= 65536 and count <= 10M individually, but not the product. a crafted snapshot with 65536 dims x 10M vectors would attempt ~2.6 TB of f32 allocation.

this adds validate_vector_total(dim, count) in format.rs that caps total f32 elements at 1 billion (~4 GB), called at both snapshot deserialization sites (encrypted and plaintext paths).

AOF VADD records store single vectors (not vector sets), so dim * count is not relevant there — no change needed.

what was tested

  • cargo test -p ember-persistence --features vector — 75/75 pass
  • cargo clippy -p ember-persistence --features vector -- -D warnings — clean
  • cargo fmt --all --check — clean

design considerations

the 1 billion total float budget (~4 GB) is generous enough for real workloads (e.g. 1024 dims x 1M vectors = 1B floats) while preventing the worst-case product of the two individual limits.

add validate_vector_total(dim, count) check after individual dim/count
validation in snapshot deserialization. without this, a crafted snapshot
with 65536 dims x 10M vectors would attempt ~2.6 TB of allocation.
the new cap limits total f32 elements to 1 billion (~4 GB).
@kacy
kacy merged commit 9ba7727 into main Feb 14, 2026
6 of 7 checks passed
@kacy
kacy deleted the security/persistence-hardening branch February 14, 2026 22:55
kacy added a commit that referenced this pull request Feb 19, 2026
add validate_vector_total(dim, count) check after individual dim/count
validation in snapshot deserialization. without this, a crafted snapshot
with 65536 dims x 10M vectors would attempt ~2.6 TB of allocation.
the new cap limits total f32 elements to 1 billion (~4 GB).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant