Skip to content

harden ember-protocol — vector dimension and HNSW parameter caps - #103

Merged
kacy merged 1 commit into
mainfrom
harden/ember-protocol
Feb 12, 2026
Merged

harden ember-protocol — vector dimension and HNSW parameter caps#103
kacy merged 1 commit into
mainfrom
harden/ember-protocol

Conversation

@kacy

@kacy kacy commented Feb 12, 2026

Copy link
Copy Markdown
Owner

summary

adds bounds checking to vector command parsing to prevent DoS through unbounded resource allocation:

  • vector dimension cap: VADD and VSIM vectors now capped at 65,536 dimensions. this is generous for any real-world embedding model (OpenAI: 1,536, Cohere: 4,096) while preventing a client from sending million-dimension vectors that consume ~4MB each.
  • HNSW parameter validation: M and EF parameters validated against a max of 1,024 before the u64 → u32 cast. values above this give no practical benefit for HNSW and waste memory. prevents silent truncation on values > u32::MAX.

what was tested

  • all 296 ember-protocol unit tests pass
  • 1 doc-test passes
  • cargo clippy -p ember-protocol clean

design considerations

  • the RESP3 parser already caps arrays at 1M elements, so the worst-case without this fix was ~1M f32 dimensions (~4MB per vector). the new 65,536 cap brings this to ~256KB which is reasonable.
  • HNSW parameter cap of 1,024 is based on the algorithm literature: M values above ~48 and EF values above ~500 show diminishing returns in recall benchmarks.

- add MAX_VECTOR_DIMS (65,536) to prevent memory abuse from absurdly
  large vectors in VADD and VSIM commands
- add MAX_HNSW_PARAM (1,024) to validate M and EF values before the
  u64→u32 cast, preventing silent truncation and pointless resource use
- all 296 existing tests pass unchanged
@kacy
kacy merged commit df70649 into main Feb 12, 2026
7 checks passed
@kacy
kacy deleted the harden/ember-protocol branch February 12, 2026 16:33
kacy added a commit that referenced this pull request Feb 19, 2026
- add MAX_VECTOR_DIMS (65,536) to prevent memory abuse from absurdly
  large vectors in VADD and VSIM commands
- add MAX_HNSW_PARAM (1,024) to validate M and EF values before the
  u64→u32 cast, preventing silent truncation and pointless resource use
- all 296 existing tests pass unchanged
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