airlift / aircompressor

A port of Snappy, LZO, LZ4, and Zstandard to Java
Apache License 2.0
568 stars 113 forks source link

ZSTD : Drive the end of decompression with both "inputLimit" and "outputLimit" #197

Open nephri opened 5 months ago

nephri commented 5 months ago

Hi, I have an input ByteBuffer with some datas i want to decompress.

I know i can decompress 65536 bytes but i don't know how many bytes in input buffer will be needed for this (but i know my input buffer contains enough data to achieve it and can decompress exactly 64K bytes)

So, i call ZstdDecompressor.decompress( ByteBufffer input , ByteBuffer output ) With exactly 65536 bytes availables to output

This method call io.airlift.compress.MalformedInputException: Output buffer too small: offset=999 because it try to decompress more than 65536 bytes.

It's because after a frame, it reach 65536 output bytes but continue because input bytes are remaining

In ZstdFrameDecompressor i would have a code like this:

150: while( input < inputLimit && output < outputLimit ) {

But also in ZstdDecompressor (like line 101), we should update position on output buffer and also on input buffer

If the outputlimit is not perfectly aligned with a frame, we should continue to have the MalformedInputException

Best regards, Sébastien.