jaideeppyne opened a new pull request, #226: URL: https://github.com/apache/datasketches-rust/pull/226
## Description `CpcSketch::deserialize` returns a `Result`, but malformed or corrupt bytes could reach the FM85 decompressor and panic rather than returning an error. A fuzzer over single-byte mutations of valid sketches found reachable panics in release builds, including: - index-out-of-bounds in `maybe_fill_bitbuf` when the compressed stream is truncated; - out-of-range window / pair-table indexing when a decoded pair row exceeds `k`; - failed asserts on the sliding-window offset and column permutation; - divide-by-zero / arithmetic overflow from inconsistent header fields. This is the same "reject invalid states on deserialize" theme as #218/#221 (REQ) and #224 (frequencies); CPC was uncovered. ## Fix The decompression read path (`uncompress` and its callees, used only during deserialization) is now fallible. `deserialize` validates the header up front — coupon-space bound on `num_coupons`, flavor-vs-flags consistency, and `table_num_entries` bounds (which also caps the decode allocation) — and the decompressor bounds-checks every compressed-word read and rejects any decoded pair whose row falls outside `[0, 2^lg_k)` before it is used. The happy-path decode logic is unchanged. ## Compatibility Valid sketches are unaffected: the Java, C++, and Go serialization round-trips still pass byte-for-byte, and a new round-trip test asserts identical estimates and re-serialized bytes across all flavors. ## Tests Adds `tests/cpc_test/deserialize.rs`: a corruption fuzzer that must never panic, targeted corruptions that must return `Err`, and a valid-sketch round-trip check. Before this change the fuzzer/targeted tests panic; after, they pass. `cargo fmt` and `cargo clippy -D warnings` are clean. Note: a separate, pre-existing 32-bit overflow in `determine_pseudo_phase` for `lg_k >= 21` (reachable from serialize as well) is out of scope here and left for a follow-up. -- 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]
