luben / zstd-jni

JNI binding for Zstd
Other
808 stars 165 forks source link

Zstd.decompressedSize(ByteBuffer) returns negative values for empty buffers (Regression 1.5.0-4 -> 1.5.5-4) #269

Closed wiltseb closed 10 months ago

wiltseb commented 12 months ago

Based on the documentation, I'd expect that Zstd.decompressedSize(ByteBuffer) would always return a non-negative value. But somewhere between 1.5.0-4 and 1.5.5-4, it began returning negative values when provided with an empty ByteBuffer. For empty ByteBuffers specifically, I would expect the method to return zero (despite the ambiguity with the return value when the size is unknown).

Somewhere between 1.5.0-4 and 1.5.5-4, Zstd.decompressedSize(ByteBuffer) began returning negative values when passed an empty ByteBuffer.

Zstd.decompressedSize(ByteBuffer.allocate(0)) 1.5.0-4 returns 1 1.5.5-4 returns -1

Zstd.decompressedSize(ByteBuffer.allocateDirect(0)) 1.5.0-4 returns 0 1.5.5-4 returns -2

luben commented 10 months ago

The returned negative integers are error codes. Zstd returns 0 if there is valid frame header but there is no size encoded there - this could happen if the frame was compressed in streaming mode.

On you errors: