Commit 0475405
committed
fix(ldm): gate behind hash feature + harden insert_absolute preconditions
`encoding::ldm` was compiled unconditionally but depends on
`twox_hash::XxHash64` for the per-window XXH64 (`zstd_ldm.c:315`).
`twox-hash` is an optional dependency behind the `hash` feature,
so `default-features = false` builds (no_std, embedded) failed to
compile. The fix mirrors the gating pattern already used for the
same crate in `streaming_encoder.rs`, `frame_compressor.rs`, and
`decode_buffer.rs`:
* `mod ldm;` declaration is `#[cfg(feature = "hash")]`.
* `BtMatcher::ldm_producer` field and every integration callsite
(`use ... LdmProducer`, `Some(producer) = self.ldm_producer
...`) carry the same gate. Under `default-features = false` the
field disappears and `prepare_ldm_candidates` reduces to its
legacy `ldm_sequences.clear()` stub.
* `prepare_ldm_candidates_translates_absolute_positions_to_slice_
indices` regression also gated.
Verified: `cargo build --lib --no-default-features` clean;
`cargo clippy --lib --tests --no-default-features -- -D warnings`
clean.
Separately, `LdmHashTable::insert_absolute` promoted its two
preconditions from `debug_assert!` to runtime panics so a
contract violation cannot silently corrupt the table in release
builds:
* `abs_pos < position_base` now panics via `checked_sub` +
`unwrap_or_else` with a diagnostic instead of underflowing the
subtraction and casting the wraparound to `u32`.
* `rel >= u32::MAX as usize` now panics via `assert!` (was
`debug_assert!`) — the producer's `ensure_room_for` rebases
before this point, but if a custom caller bypasses it the
failure is loud and immediate.
* The `+1` empty-slot bias was moved inside the `u32` arithmetic
(`(rel as u32) + 1` instead of `(rel + 1) as u32`) so the
intermediate `usize` add can't overflow on 32-bit targets.
New `insert_absolute_panics_below_position_base` regression
covers the underflow guard with `#[should_panic]`.
README quick-start snippet now passes `&b"hello world"[..]` to
`compress_to_vec` — `b"..."` literal alone is `&[u8; N]` which
does not implement `std::io::Read`, so the doctest failed under
`cargo test --doc` after the earlier doc rewrite landed.
469 lib tests + 11 doctests pass; clippy clean under default
features AND under `--no-default-features`.1 parent 201e7c5 commit 0475405
4 files changed
Lines changed: 69 additions & 6 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
17 | 17 | | |
18 | 18 | | |
19 | 19 | | |
20 | | - | |
| 20 | + | |
21 | 21 | | |
22 | 22 | | |
23 | 23 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
20 | 20 | | |
21 | 21 | | |
22 | 22 | | |
| 23 | + | |
23 | 24 | | |
24 | 25 | | |
25 | 26 | | |
| |||
70 | 71 | | |
71 | 72 | | |
72 | 73 | | |
73 | | - | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
74 | 81 | | |
75 | 82 | | |
76 | 83 | | |
| |||
123 | 130 | | |
124 | 131 | | |
125 | 132 | | |
| 133 | + | |
126 | 134 | | |
127 | 135 | | |
128 | 136 | | |
| |||
146 | 154 | | |
147 | 155 | | |
148 | 156 | | |
| 157 | + | |
149 | 158 | | |
150 | 159 | | |
151 | 160 | | |
| |||
359 | 368 | | |
360 | 369 | | |
361 | 370 | | |
| 371 | + | |
362 | 372 | | |
363 | 373 | | |
364 | 374 | | |
| |||
372 | 382 | | |
373 | 383 | | |
374 | 384 | | |
| 385 | + | |
| 386 | + | |
| 387 | + | |
| 388 | + | |
| 389 | + | |
| 390 | + | |
| 391 | + | |
| 392 | + | |
| 393 | + | |
| 394 | + | |
| 395 | + | |
| 396 | + | |
| 397 | + | |
375 | 398 | | |
376 | 399 | | |
377 | 400 | | |
| |||
700 | 723 | | |
701 | 724 | | |
702 | 725 | | |
| 726 | + | |
703 | 727 | | |
704 | 728 | | |
705 | 729 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
271 | 271 | | |
272 | 272 | | |
273 | 273 | | |
274 | | - | |
275 | | - | |
276 | | - | |
| 274 | + | |
| 275 | + | |
| 276 | + | |
| 277 | + | |
| 278 | + | |
| 279 | + | |
| 280 | + | |
| 281 | + | |
| 282 | + | |
| 283 | + | |
| 284 | + | |
| 285 | + | |
| 286 | + | |
| 287 | + | |
277 | 288 | | |
278 | 289 | | |
279 | 290 | | |
280 | 291 | | |
281 | 292 | | |
282 | | - | |
| 293 | + | |
| 294 | + | |
| 295 | + | |
| 296 | + | |
| 297 | + | |
| 298 | + | |
283 | 299 | | |
284 | 300 | | |
285 | 301 | | |
| |||
575 | 591 | | |
576 | 592 | | |
577 | 593 | | |
| 594 | + | |
| 595 | + | |
| 596 | + | |
| 597 | + | |
| 598 | + | |
| 599 | + | |
| 600 | + | |
| 601 | + | |
| 602 | + | |
| 603 | + | |
| 604 | + | |
| 605 | + | |
| 606 | + | |
| 607 | + | |
578 | 608 | | |
579 | 609 | | |
580 | 610 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
45 | 45 | | |
46 | 46 | | |
47 | 47 | | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
48 | 57 | | |
49 | 58 | | |
50 | 59 | | |
| |||
0 commit comments