CodecZstd.jl icon indicating copy to clipboard operation
CodecZstd.jl copied to clipboard

Detect truncated frames to avoid infinite loop

Open nhz2 opened this issue 1 year ago • 1 comments

Fixes #24

The streaming decompression function will only return zero when a frame is fully decoded and flushed out. If the return value is not an error it will be less than or equal to the number of bytes left in the frame that haven't been read yet. If process is called with input.size==0 there is no more data left to decompress.

So if there is no more data left to decompress, but zstd is asking for more data, then the frame is truncated, and error should be returned. Ref: https://github.com/facebook/zstd/issues/340#issuecomment-245942328 https://github.com/facebook/zstd/issues/1109 https://github.com/facebook/zstd/blob/dev/examples/streaming_decompression.c

nhz2 avatar May 19 '24 00:05 nhz2

Codecov Report

All modified and coverable lines are covered by tests :white_check_mark:

Project coverage is 31.84%. Comparing base (4c799fe) to head (a62e8c9).

Additional details and impacted files
@@            Coverage Diff             @@
##           master      #47      +/-   ##
==========================================
+ Coverage   30.98%   31.84%   +0.86%     
==========================================
  Files           5        5              
  Lines         510      515       +5     
==========================================
+ Hits          158      164       +6     
+ Misses        352      351       -1     

:umbrella: View full report in Codecov by Sentry.
:loudspeaker: Have feedback on the report? Share it here.

codecov[bot] avatar May 19 '24 00:05 codecov[bot]