Commit b0e51af
authored
## What
Two fixes in the compression codec:
1. **`AbstractCompressionCodec.compress()`: capture `writerIndex()`
once**
The previous code read `uncompressedBuffer.writerIndex()` at multiple
sites — for the size comparison and again after `doCompress()` to
populate the 8-byte uncompressed-length prefix. Capture the value once
at the top of `compress()` and reuse it for the empty-buffer check, the
size comparison, and the prefix, so all three consumers see the same
value.
2. **`ZstdCompressionCodec.doCompress()`: `dstCapacity` overstated by 8
bytes**
`Zstd.compressUnsafe(dst, dstSize, ...)` expects `dstSize` to be the
available space from `dst`. The code offsets `dst` by 8 bytes past the
prefix but passed `8 + maxSize` instead of `maxSize`. The
`compressBound()` headroom hides this in practice, but the parameter was
semantically wrong. Pass `maxSize`.
## Tests
Covered by the existing round-trip tests (`testEmptyBuffer`,
`testReadWriteStream`, `testReadWriteFile`, etc.). I was not able to
construct a minimal reproducer for the original `declaredUncompressed=0`
symptom on the unfixed code, so both fixes are conservative correctness
improvements derived from code inspection rather than failing-then-green
regression tests.
1 parent 9122af2 commit b0e51af
2 files changed
Lines changed: 6 additions & 3 deletions
File tree
- compression/src/main/java/org/apache/arrow/compression
- vector/src/main/java/org/apache/arrow/vector/compression
Lines changed: 1 addition & 1 deletion
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
44 | 44 | | |
45 | 45 | | |
46 | 46 | | |
47 | | - | |
| 47 | + | |
48 | 48 | | |
49 | 49 | | |
50 | 50 | | |
| |||
Lines changed: 5 additions & 2 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
29 | 29 | | |
30 | 30 | | |
31 | 31 | | |
32 | | - | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
33 | 37 | | |
34 | 38 | | |
35 | 39 | | |
| |||
41 | 45 | | |
42 | 46 | | |
43 | 47 | | |
44 | | - | |
45 | 48 | | |
46 | 49 | | |
47 | 50 | | |
| |||
0 commit comments