Commit f3dadfe
fix: correct pruning condition in RS Decode for last part padding (#2794)
## Summary
- Fix a bug in `Decode` (`types/part_set.go`) where
`len(data[:(ops.Total()-1)])` compared a **part count** against
`lastPartLen` (a **byte length**). When `Total-1` numerically equaled
`lastPartLen`, pruning of RS padding was skipped, causing a Merkle root
mismatch and breaking RS recovery for block data sizes of `k * 65537`
bytes.
- Change the condition to `len(data[ops.Total()-1])` which correctly
compares the byte length of the last reconstructed part against the
expected unpadded length.
- Extract the pruning logic into a standalone `pruneLastPart` function
for testability.
- Replace the complex `TestDecodePruningBug` (which spun up full RS
encode/decode machinery) with a focused `TestPruneLastPart` unit test
that directly exercises the extracted function.
## Test plan
- [x] `TestPruneLastPart` passes for both subtests (prunes when padded,
no-op when already correct)
- [x] Existing `TestEncodingDecodingRoundTrip` continues to pass
- [ ] Run full `go test ./types/` suite
🤖 Generated with [Claude Code](https://claude.com/claude-code)
---------
Co-authored-by: Claude Opus 4.6 <noreply@anthropic.com>1 parent f968cad commit f3dadfe
2 files changed
+29
-3
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
363 | 363 | | |
364 | 364 | | |
365 | 365 | | |
| 366 | + | |
| 367 | + | |
| 368 | + | |
| 369 | + | |
| 370 | + | |
| 371 | + | |
| 372 | + | |
| 373 | + | |
366 | 374 | | |
367 | 375 | | |
368 | 376 | | |
| |||
410 | 418 | | |
411 | 419 | | |
412 | 420 | | |
413 | | - | |
414 | | - | |
415 | | - | |
| 421 | + | |
416 | 422 | | |
417 | 423 | | |
418 | 424 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
141 | 141 | | |
142 | 142 | | |
143 | 143 | | |
| 144 | + | |
| 145 | + | |
| 146 | + | |
| 147 | + | |
| 148 | + | |
| 149 | + | |
| 150 | + | |
| 151 | + | |
| 152 | + | |
| 153 | + | |
| 154 | + | |
| 155 | + | |
| 156 | + | |
| 157 | + | |
| 158 | + | |
| 159 | + | |
| 160 | + | |
| 161 | + | |
| 162 | + | |
| 163 | + | |
144 | 164 | | |
145 | 165 | | |
146 | 166 | | |
| |||
0 commit comments