align caller-supplied buffer in value_stack::stack - #1193
Conversation
|
An automated preview of the documentation is available at https://1193.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-09-08 16:28:23 UTC |
|
GCOVR code coverage report https://1193.json.prtest2.cppalliance.org/gcovr/index.html Build time: 2026-09-08 16:48:01 UTC |
|
|
86dfe9a to
37912e9
Compare
|
Rebased onto develop to pick up the GCC 16 CI fix (82398f9); the failing Drone stages were the null_resource.cpp -Wfree-nonheap-object error, not this change. No code changes. |
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## develop #1193 +/- ##
========================================
Coverage 93.72% 93.72%
========================================
Files 85 85
Lines 8981 8982 +1
========================================
+ Hits 8417 8418 +1
Misses 564 564
Continue to review full report in Codecov by Harness.
🚀 New features to boost your workflow:
|
|
|


Repro: hand any of the buffer-taking parser / stream_parser / value_stack constructors a buffer that is not aligned for
value(buf + 1, a heap block, a sub-buffer) and parse a small array. UBSan reportsconstructor call on misaligned address ... for type boost::json::value, which requires 8 byte alignmentatdetail/value.hpp:229, viavalue_stack::stack::push.Cause:
value_stack::stackstoresvalueobjects in the caller-owned buffer but reinterprets it asvalue*without aligning the pointer.static_resource::do_allocateandmonotonic_resourceboth align a caller buffer throughstd::align; this constructor was the one that skipped it, and the buffer overloads document the parameter only as "a pointer to valid storage".Fix: align the buffer up to
alignof(value)withstd::align, keepingmin_size_ * sizeof(value)usable bytes, and fall back to the memory resource when the aligned region is too small.Regression test walks every misalignment of a value-sized buffer and parses
[1,2,3]; the odd offsets trip UBSan before the change and pass after.