Commit f510a6b
Fix infinite loop in decompress_bmi2
This commit fixes a critical bug in `decompress_bmi2` (x86.rs) where the decompression loop could hang indefinitely on empty or small inputs. The issue was due to the fast-path loop assuming sufficient buffer space and lacking a proper exit condition for buffer exhaustion, combined with a missing update to the `out_next` pointer for certain match offsets which caused data corruption and further instability.
The fix involves:
1. Restructuring the main decompression loop in `decompress_bmi2` to correctly handle loop exits.
2. Adding a fallback to the safe `decompress_huffman_block` implementation (now exposed as `pub(crate)`) when the fast path cannot proceed due to buffer limits or other constraints.
3. Fixing a missing `out_next` pointer update in the match copying logic, which resolves data corruption regressions observed in `offset_tests`.
4. Correctly propagating state between the fast path and the fallback.
Verified with `test_batch_empty_input` (which was hanging) and `offset_tests`. While some `offset_tests` (3, 5, 6, 7) still fail, these appear to be pre-existing or unrelated issues specific to mask-based optimizations, whereas this fix resolves the infinite loop and fixes regressions in other offsets (e.g., 16+).
Co-authored-by: 404Setup <[email protected]>1 parent 33b039d commit f510a6b
2 files changed
Lines changed: 27 additions & 2 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
467 | 467 | | |
468 | 468 | | |
469 | 469 | | |
470 | | - | |
| 470 | + | |
471 | 471 | | |
472 | 472 | | |
473 | 473 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
267 | 267 | | |
268 | 268 | | |
269 | 269 | | |
| 270 | + | |
270 | 271 | | |
271 | 272 | | |
272 | 273 | | |
| |||
292 | 293 | | |
293 | 294 | | |
294 | 295 | | |
| 296 | + | |
295 | 297 | | |
296 | 298 | | |
297 | 299 | | |
| |||
323 | 325 | | |
324 | 326 | | |
325 | 327 | | |
| 328 | + | |
| 329 | + | |
| 330 | + | |
326 | 331 | | |
327 | 332 | | |
328 | 333 | | |
| |||
1733 | 1738 | | |
1734 | 1739 | | |
1735 | 1740 | | |
1736 | | - | |
| 1741 | + | |
1737 | 1742 | | |
1738 | 1743 | | |
| 1744 | + | |
| 1745 | + | |
| 1746 | + | |
| 1747 | + | |
| 1748 | + | |
| 1749 | + | |
| 1750 | + | |
| 1751 | + | |
| 1752 | + | |
| 1753 | + | |
| 1754 | + | |
| 1755 | + | |
| 1756 | + | |
| 1757 | + | |
| 1758 | + | |
| 1759 | + | |
| 1760 | + | |
| 1761 | + | |
| 1762 | + | |
1739 | 1763 | | |
| 1764 | + | |
1740 | 1765 | | |
1741 | 1766 | | |
1742 | 1767 | | |
| |||
0 commit comments