Skip to content

Add bounds check in cbor_array_get() - #388

Merged
PJK merged 1 commit into
masterfrom
fix-array-get-bounds-check
Feb 8, 2026
Merged

PJK merged 1 commit into
masterfrom
fix-array-get-bounds-check

Conversation

@PJK

@PJK PJK commented Feb 8, 2026

Copy link
Copy Markdown
Owner

Summary

  • cbor_array_get() header documents returning NULL on boundary violation, but the implementation had no check and would perform an out-of-bounds read
  • Add a bounds check against end_ptr and return NULL when the index is out of range
  • Add CBOR_ASSERT(cbor_isa_array(item)) for consistency with other array functions

Test plan

  • Added test_array_get_out_of_bounds covering: valid index, index == size, index > size, and empty array
  • All 26 test binaries pass
  • clang-format clean

🤖 Generated with Claude Code

The header documents returning NULL on out-of-bounds access, but the
implementation had no check and would read arbitrary memory. Add the
bounds check against end_ptr and return NULL when index is out of range.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@PJK
PJK force-pushed the fix-array-get-bounds-check branch from 2ed46ba to 02590db Compare February 8, 2026 17:17
@PJK
PJK merged commit 5b0e20c into master Feb 8, 2026
15 of 17 checks passed
@PJK
PJK deleted the fix-array-get-bounds-check branch February 8, 2026 17:19
@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 99.87%. Comparing base (3412f97) to head (02590db).
⚠️ Report is 35 commits behind head on master.

Additional details and impacted files
@@             Coverage Diff             @@
##            master     #388      +/-   ##
===========================================
- Coverage   100.00%   99.87%   -0.13%     
===========================================
  Files           20       20              
  Lines         1657     1659       +2     
===========================================
  Hits          1657     1657              
- Misses           0        2       +2     

☔ 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.

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

⌂ 换网址