Skip to content

fix array index overflow in set_at_pointer - #1192

Open
Ramya-9353 wants to merge 2 commits into
boostorg:developfrom
Ramya-9353:pointer-set-index-overflow
Open

fix array index overflow in set_at_pointer#1192
Ramya-9353 wants to merge 2 commits into
boostorg:developfrom
Ramya-9353:pointer-set-index-overflow

Conversation

@Ramya-9353

@Ramya-9353 Ramya-9353 commented Aug 24, 2026

Copy link
Copy Markdown
Contributor

Repro: call set_at_pointer on a non-empty array with an index token equal to std::size_t(-1), e.g. "/18446744073709551615" on a 64-bit build, and a max_created_elements large enough to pass the element-count guard.

Cause: the guard bounds n (the number of elements to create) but not index + 1. arr.size() + n + 1 is index + 1, which wraps to 0, so resize takes the shrink branch (skipping the array_too_large check) and the lambda returns arr.data() + index, a pointer one element before the buffer. The following *result = ref.make_value(...) then writes through it (ASAN: heap-buffer-overflow in value::operator= via pointer.ipp:490; UBSan: unsigned pointer overflow at pointer.ipp:462).

Fix: reject index >= array::max_size() before the resize and fail with error::array_too_large, next to the existing max_created_elements check. Regression test drives index std::size_t(-1) on a non-empty array and checks the array is untouched and error::array_too_large is returned.

@cppalliance-bot

cppalliance-bot commented Aug 24, 2026

Copy link
Copy Markdown

An automated preview of the documentation is available at https://1192.json.prtest2.cppalliance.org/libs/json/doc/html/index.html

If more commits are pushed to the pull request, the docs will rebuild at the same URL.

2026-08-27 09:39:05 UTC

@cppalliance-bot

cppalliance-bot commented Aug 24, 2026

Copy link
Copy Markdown

GCOVR code coverage report https://1192.json.prtest2.cppalliance.org/gcovr/index.html
LCOV code coverage report https://1192.json.prtest2.cppalliance.org/genhtml/index.html
Coverage Diff Report https://1192.json.prtest2.cppalliance.org/diff-report/index.html

Build time: 2026-08-27 09:49:19 UTC

@cppalliance-bot

Copy link
Copy Markdown

@codecov

codecov Bot commented Aug 24, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 93.72%. Comparing base (e0e74f6) to head (4be012d).

Additional details and impacted files

Impacted file tree graph

@@           Coverage Diff            @@
##           develop    #1192   +/-   ##
========================================
  Coverage    93.72%   93.72%           
========================================
  Files           85       85           
  Lines         8981     8983    +2     
========================================
+ Hits          8417     8419    +2     
  Misses         564      564           
Files with missing lines Coverage Δ
include/boost/json/impl/pointer.ipp 100.00% <100.00%> (ø)

Continue to review full report in Codecov by Harness.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update e0e74f6...4be012d. Read the comment docs.

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

Comment thread include/boost/json/impl/pointer.ipp
@cppalliance-bot

Copy link
Copy Markdown

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.

3 participants