Commit b39a576
committed
fix(codec): address PR-195 review — overflow Merge alias + mode-sized pack_leaf
P1 (codex) — overflow δ no longer aliases to Merge:
predict_intra previously took `our_delta_u8 = δ as u8` BEFORE
checking i8 fit, so e.g. δ=200 wrapped to 0xC8 and could match a
neighbour byte 0xC8 (i8=-56), silently corrupting reconstruction.
Now the i8 range check gates both the Merge scan and the Delta
branch; out-of-range δ falls straight through to Escape (or the
documented lossy clamp).
+ 2 regression tests:
- overflow_delta_does_not_alias_to_merge
- overflow_delta_with_allocator_takes_escape
P2 (coderabbit + codex) — pack_leaf accepts mode-sized buffers:
pack_leaf used a 6-byte minimum for all modes; callers pre-sizing
by packed_byte_len() got spurious None for Skip(2)/Merge,Delta(3).
Length check now gates on packed_byte_len(leaf.mode).
+ 1 regression test: pack_leaf_accepts_mode_sized_buffers
P3 (coderabbit) — doctest examples on the public-API surface:
Added /// runnable examples to MAX_BASIN_IDX, BASIN_NONE,
unpack_header, pack_merge_dir, unpack_merge_dir, unpack_leaf,
packed_byte_len, IntraContext, IntraConfig, is_no_basin.
Removed unused LeafCu import from existing predict_intra doctest.
Gates:
cargo test --features codec --lib hpc::codec → 48 passed
cargo test --features codec --doc hpc::codec → 14 passed
cargo fmt --all -- --check → clean
cargo clippy --features codec --lib -- -D warnings → clean1 parent 26d987f commit b39a576
2 files changed
Lines changed: 148 additions & 17 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
57 | 57 | | |
58 | 58 | | |
59 | 59 | | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
60 | 65 | | |
61 | 66 | | |
62 | 67 | | |
63 | 68 | | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
64 | 74 | | |
65 | 75 | | |
66 | 76 | | |
| |||
85 | 95 | | |
86 | 96 | | |
87 | 97 | | |
| 98 | + | |
| 99 | + | |
| 100 | + | |
| 101 | + | |
| 102 | + | |
| 103 | + | |
88 | 104 | | |
89 | 105 | | |
90 | 106 | | |
| |||
103 | 119 | | |
104 | 120 | | |
105 | 121 | | |
| 122 | + | |
| 123 | + | |
| 124 | + | |
| 125 | + | |
| 126 | + | |
106 | 127 | | |
107 | 128 | | |
108 | 129 | | |
| |||
112 | 133 | | |
113 | 134 | | |
114 | 135 | | |
| 136 | + | |
| 137 | + | |
| 138 | + | |
| 139 | + | |
| 140 | + | |
| 141 | + | |
| 142 | + | |
115 | 143 | | |
116 | 144 | | |
117 | 145 | | |
| |||
133 | 161 | | |
134 | 162 | | |
135 | 163 | | |
136 | | - | |
| 164 | + | |
| 165 | + | |
| 166 | + | |
137 | 167 | | |
138 | 168 | | |
139 | 169 | | |
| |||
151 | 181 | | |
152 | 182 | | |
153 | 183 | | |
154 | | - | |
| 184 | + | |
| 185 | + | |
155 | 186 | | |
156 | 187 | | |
157 | 188 | | |
| |||
184 | 215 | | |
185 | 216 | | |
186 | 217 | | |
| 218 | + | |
| 219 | + | |
| 220 | + | |
| 221 | + | |
| 222 | + | |
| 223 | + | |
| 224 | + | |
| 225 | + | |
| 226 | + | |
| 227 | + | |
187 | 228 | | |
188 | 229 | | |
189 | 230 | | |
| |||
217 | 258 | | |
218 | 259 | | |
219 | 260 | | |
| 261 | + | |
| 262 | + | |
| 263 | + | |
| 264 | + | |
| 265 | + | |
| 266 | + | |
| 267 | + | |
| 268 | + | |
220 | 269 | | |
221 | 270 | | |
222 | 271 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
87 | 87 | | |
88 | 88 | | |
89 | 89 | | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
| 95 | + | |
| 96 | + | |
| 97 | + | |
| 98 | + | |
| 99 | + | |
| 100 | + | |
90 | 101 | | |
91 | 102 | | |
92 | 103 | | |
| |||
102 | 113 | | |
103 | 114 | | |
104 | 115 | | |
| 116 | + | |
| 117 | + | |
| 118 | + | |
| 119 | + | |
| 120 | + | |
| 121 | + | |
| 122 | + | |
| 123 | + | |
105 | 124 | | |
106 | 125 | | |
107 | 126 | | |
| |||
139 | 158 | | |
140 | 159 | | |
141 | 160 | | |
142 | | - | |
| 161 | + | |
143 | 162 | | |
144 | 163 | | |
145 | 164 | | |
| |||
170 | 189 | | |
171 | 190 | | |
172 | 191 | | |
| 192 | + | |
| 193 | + | |
| 194 | + | |
| 195 | + | |
| 196 | + | |
| 197 | + | |
| 198 | + | |
| 199 | + | |
173 | 200 | | |
174 | 201 | | |
175 | 202 | | |
| |||
186 | 213 | | |
187 | 214 | | |
188 | 215 | | |
189 | | - | |
190 | | - | |
191 | | - | |
192 | | - | |
193 | | - | |
| 216 | + | |
| 217 | + | |
| 218 | + | |
| 219 | + | |
| 220 | + | |
| 221 | + | |
| 222 | + | |
| 223 | + | |
| 224 | + | |
| 225 | + | |
| 226 | + | |
| 227 | + | |
| 228 | + | |
| 229 | + | |
194 | 230 | | |
195 | | - | |
196 | | - | |
197 | | - | |
198 | | - | |
199 | | - | |
200 | | - | |
201 | | - | |
202 | | - | |
203 | 231 | | |
204 | 232 | | |
205 | 233 | | |
| |||
208 | 236 | | |
209 | 237 | | |
210 | 238 | | |
211 | | - | |
| 239 | + | |
212 | 240 | | |
213 | 241 | | |
214 | 242 | | |
| |||
244 | 272 | | |
245 | 273 | | |
246 | 274 | | |
| 275 | + | |
| 276 | + | |
| 277 | + | |
| 278 | + | |
| 279 | + | |
| 280 | + | |
247 | 281 | | |
248 | 282 | | |
249 | 283 | | |
| |||
394 | 428 | | |
395 | 429 | | |
396 | 430 | | |
| 431 | + | |
| 432 | + | |
| 433 | + | |
| 434 | + | |
| 435 | + | |
| 436 | + | |
| 437 | + | |
| 438 | + | |
| 439 | + | |
| 440 | + | |
| 441 | + | |
| 442 | + | |
| 443 | + | |
| 444 | + | |
| 445 | + | |
| 446 | + | |
| 447 | + | |
| 448 | + | |
| 449 | + | |
| 450 | + | |
| 451 | + | |
| 452 | + | |
| 453 | + | |
| 454 | + | |
| 455 | + | |
| 456 | + | |
| 457 | + | |
| 458 | + | |
| 459 | + | |
| 460 | + | |
| 461 | + | |
| 462 | + | |
| 463 | + | |
| 464 | + | |
| 465 | + | |
| 466 | + | |
| 467 | + | |
| 468 | + | |
| 469 | + | |
| 470 | + | |
| 471 | + | |
| 472 | + | |
| 473 | + | |
| 474 | + | |
| 475 | + | |
| 476 | + | |
| 477 | + | |
| 478 | + | |
397 | 479 | | |
0 commit comments