Zakir032002 opened a new pull request, #3421:
URL: https://github.com/apache/fory/pull/3421

   ## Summary
   
   Fixes #3409
   
   Adds three opt-in `Fory` builder methods that let callers enforce upper 
bounds on the size of data allocated during deserialization. Without these 
guards a crafted payload can contain an absurdly large length prefix, causing 
`Vec::with_capacity` / string allocation to exhaust heap memory before a single 
byte of real data is read.
   
   ```rust
   let fory = Fory::default()
       .max_string_bytes(1024 * 1024)    // 1 MB per string
       .max_collection_size(100_000)     // 100 k elements per Vec / Set
       .max_map_size(100_000);           // 100 k entries per HashMap / BTreeMap
   ```
   
   All three limits default to `None` (no limit), so this is **100 % 
backwards-compatible**.
   
   ---
   
   ## Files changed
   
   | File | What changed |
   |---|---|
   | `fory-core/src/config.rs` | Three `Option<usize>` fields: 
`max_string_bytes`, `max_collection_size`, `max_map_size` |
   | `fory-core/src/resolver/context.rs` | `check_string_bytes(len)`, 
`check_collection_size(len)`, `check_map_size(len)` helper methods on 
`ReadContext` |
   | `fory-core/src/fory.rs` | Builder methods `max_string_bytes`, 
`max_collection_size`, `max_map_size` |
   | `fory-core/src/buffer.rs` | `read_varuint36small()` public helper (needed 
by string check) |
   | `fory-core/src/serializer/string.rs` | Call `check_string_bytes` before 
allocating the string |
   | `fory-core/src/serializer/collection.rs` | Call `check_collection_size` in 
generic Vec / collection read paths |
   | `fory-core/src/serializer/primitive_list.rs` | Call 
`check_collection_size` in the `Vec<primitive>` fast path |
   | `fory-core/src/serializer/map.rs` | Call `check_map_size` before 
allocating HashMap / BTreeMap |
   | `tests/tests/test_size_guardrails.rs` | 6 integration tests (limit 
exceeded → error, within limit → ok) for all three guardrails |
   | `tests/tests/mod.rs` | Register `test_size_guardrails` module |
   
   ---
   
   ## Testing
   
   ```
   cargo fmt --check   ✓
   cargo clippy --all-targets --all-features -- -D warnings   ✓
   cargo test test_size_guardrails   → 6 passed, 0 failed
   cargo test                        → all existing tests pass
   ```


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to