Skip to content

fix: ZstdInputStream decompression failure when underlying stream returns 0 then -1 at frame boundary#372

Merged
luben merged 1 commit intoluben:masterfrom
takaaki7:fix_decompress_failure_when_srcsize_0
Jan 22, 2026
Merged

fix: ZstdInputStream decompression failure when underlying stream returns 0 then -1 at frame boundary#372
luben merged 1 commit intoluben:masterfrom
takaaki7:fix_decompress_failure_when_srcsize_0

Conversation

@takaaki7
Copy link
Copy Markdown
Contributor

Summary

  • Fix decompression failure when underlying InputStream returns 0 (no data available) followed by -1 (EOF) at a frame boundary
  • The bug caused frameFinished to remain false even when a frame was complete, leading to "Truncated source" error
  • Only set frameFinished = false when actually reading data (srcSize > 0), and skip when srcSize == 0

Test plan

  • Added test: underlying stream returning 0 then -1 mid-frame (should throw ZstdIOException for truncated data)
  • Added test: underlying stream returning 0 then data then -1 mid-frame (should succeed)
  • Added test: underlying stream returning 0 then -1 at frame boundary (should succeed and return -1 on subsequent reads)

…urns 0 then -1

When the underlying InputStream returned 0 bytes (no data available)
followed by -1 (EOF) at a frame boundary, decompression would fail with
"Truncated source" error because frameFinished remained false.

Fix: only set frameFinished = false when srcSize > 0, and continue the
loop when srcSize == 0 to retry reading.
@luben
Copy link
Copy Markdown
Owner

luben commented Jan 22, 2026

Thanks for catching that bug! LGTM

@codecov
Copy link
Copy Markdown

codecov bot commented Jan 22, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 60.81%. Comparing base (c76455c) to head (081b152).
⚠️ Report is 64 commits behind head on master.

Additional details and impacted files
@@             Coverage Diff              @@
##             master     #372      +/-   ##
============================================
+ Coverage     60.01%   60.81%   +0.79%     
- Complexity      308      334      +26     
============================================
  Files            26       27       +1     
  Lines          1473     1623     +150     
  Branches        170      192      +22     
============================================
+ Hits            884      987     +103     
- Misses          434      465      +31     
- Partials        155      171      +16     
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@luben luben merged commit d82feda into luben:master Jan 22, 2026
7 of 8 checks passed
dongjoon-hyun added a commit to apache/spark that referenced this pull request Feb 10, 2026
### What changes were proposed in this pull request?

This PR aims to upgrade `zstd-jni` to 1.5.7-7.

### Why are the changes needed?

To use the latest bug fixes:
- https://github.com/luben/zstd-jni/releases/tag/v1.5.7-7
  - luben/zstd-jni#372
  - luben/zstd-jni#374

### Does this PR introduce _any_ user-facing change?

No.

### How was this patch tested?

Pass the CIs.

### Was this patch authored or co-authored using generative AI tooling?

Generated-by: `Gemini 3 Pro (High)` on `Antigravity`

Closes #54233 from dongjoon-hyun/SPARK-55456.

Authored-by: Dongjoon Hyun <[email protected]>
Signed-off-by: Dongjoon Hyun <[email protected]>
rpnkv pushed a commit to rpnkv/spark that referenced this pull request Feb 18, 2026
### What changes were proposed in this pull request?

This PR aims to upgrade `zstd-jni` to 1.5.7-7.

### Why are the changes needed?

To use the latest bug fixes:
- https://github.com/luben/zstd-jni/releases/tag/v1.5.7-7
  - luben/zstd-jni#372
  - luben/zstd-jni#374

### Does this PR introduce _any_ user-facing change?

No.

### How was this patch tested?

Pass the CIs.

### Was this patch authored or co-authored using generative AI tooling?

Generated-by: `Gemini 3 Pro (High)` on `Antigravity`

Closes apache#54233 from dongjoon-hyun/SPARK-55456.

Authored-by: Dongjoon Hyun <[email protected]>
Signed-off-by: Dongjoon Hyun <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants