Skip to content

Address potential unsigned underflow in streaming decoder claim_bytes()#389

Merged
PJK merged 1 commit into
masterfrom
fix-claim-bytes-underflow
Feb 8, 2026
Merged

Address potential unsigned underflow in streaming decoder claim_bytes()#389
PJK merged 1 commit into
masterfrom
fix-claim-bytes-underflow

Conversation

@PJK

@PJK PJK commented Feb 8, 2026

Copy link
Copy Markdown
Owner

Summary

  • claim_bytes() in streaming.c computes provided - result->read as size_t, which would underflow if result->read > provided
  • In practice this can't happen because result->read is only incremented on successful claims, but the invariant was implicit
  • Add an assertion and comment documenting why the subtraction is safe

Test plan

  • All 26 test binaries pass
  • clang-format clean

🤖 Generated with Claude Code

@codecov

codecov Bot commented Feb 8, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 100.00%. Comparing base (5b0e20c) to head (f415463).
⚠️ Report is 34 commits behind head on master.

Additional details and impacted files
@@            Coverage Diff            @@
##            master      #389   +/-   ##
=========================================
  Coverage   100.00%   100.00%           
=========================================
  Files           20        20           
  Lines         1659      1659           
=========================================
  Hits          1659      1659           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@PJK
PJK force-pushed the fix-claim-bytes-underflow branch from 1fea050 to 422ae3e Compare February 8, 2026 17:38
@PJK PJK changed the title Fix potential unsigned underflow in streaming decoder claim_bytes() Address potential unsigned underflow in streaming decoder claim_bytes() Feb 8, 2026
The subtraction `provided - result->read` is computed as size_t. If
result->read were ever greater than provided, this would underflow to
a huge value, bypassing the bounds check. Rewrite as
`required + result->read > provided` to avoid the subtraction entirely.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@PJK
PJK force-pushed the fix-claim-bytes-underflow branch from 422ae3e to f415463 Compare February 8, 2026 17:41
@PJK
PJK merged commit 50d8718 into master Feb 8, 2026
14 of 17 checks passed
@PJK
PJK deleted the fix-claim-bytes-underflow branch February 8, 2026 17:42
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.

1 participant