Skip to content

Fix integer overflow in cbor_copy_definite() chunk accumulation - #387

Merged
PJK merged 2 commits into
masterfrom
fix-cbor-copy-definite-overflow
Feb 8, 2026
Merged

PJK merged 2 commits into
masterfrom
fix-cbor-copy-definite-overflow

Conversation

@PJK

@PJK PJK commented Feb 8, 2026

Copy link
Copy Markdown
Owner

Summary

  • Fix integer overflow when summing chunk lengths in cbor_copy_definite() for indefinite bytestrings and strings
  • Crafted chunks with lengths summing past SIZE_MAX would silently wrap around, causing a small _cbor_malloc followed by heap buffer overflow in memcpy
  • Use existing _cbor_safe_to_add() to detect overflow and return NULL

Test plan

  • Added test_definite_indef_bytestring_chunk_length_overflow — verifies cbor_copy_definite() returns NULL when bytestring chunk lengths would overflow
  • Added test_definite_indef_string_chunk_length_overflow — same for strings
  • All 26 existing test binaries pass
  • clang-format clean

🤖 Generated with Claude Code

PJK and others added 2 commits February 8, 2026 18:08
When flattening indefinite bytestrings/strings, chunk lengths were
summed without overflow checks. Crafted chunks summing past SIZE_MAX
would wrap around, causing a small allocation followed by a heap
buffer overflow in memcpy. Use _cbor_safe_to_add() to detect overflow
and return NULL.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@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 (d3e40ca) to head (27399d4).
⚠️ Report is 36 commits behind head on master.

Additional details and impacted files
@@            Coverage Diff            @@
##            master      #387   +/-   ##
=========================================
  Coverage   100.00%   100.00%           
=========================================
  Files           20        20           
  Lines         1653      1657    +4     
=========================================
+ Hits          1653      1657    +4     

☔ 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 merged commit 3412f97 into master Feb 8, 2026
16 of 18 checks passed
@PJK
PJK deleted the fix-cbor-copy-definite-overflow branch February 8, 2026 17:11
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

⌂ 换网址