Skip to content

Commit 2f854bb

Browse files
Fix data corruption in decompress_huffman_block for small offsets
The generic decompression logic in `src/decompress/mod.rs` (`decompress_huffman_block`) contained unsafe optimizations for offsets 3, 5, 6, and 7. These optimizations performed unaligned 8-byte reads from the source pointer (`dest - offset`) that extended into uninitialized destination memory. This Undefined Behavior caused data corruption, manifesting as single-byte errors in `test_offset_7_pattern`. This patch: 1. Removes the unsafe optimized blocks for offsets 3, 5, 6, and 7 in `src/decompress/mod.rs`, falling back to a safe scalar copy loop. 2. Removes similar complex/buggy SIMD logic for offsets 3, 5, 6, 7 in `src/decompress/x86.rs` to ensure correctness and simplicity, as the fast path logic mirrored the flawed approach. 3. Fixes `test_offset_7_pattern` failure. The issue was difficult to diagnose because `test_offset_7_pattern` uses a small input buffer, causing `decompress_bmi2` (fast path) to be skipped in favor of the generic `decompress_huffman_block` (slow path), masking changes made only to the x86 implementation. Co-authored-by: 404Setup <[email protected]>
1 parent b2c86a6 commit 2f854bb

2 files changed

Lines changed: 10 additions & 806 deletions

File tree

0 commit comments

Comments
 (0)