Repository navigation
x3 parser: do not read str/bin/ext through a non-contiguous range - #1236
Conversation
The x3 str/bin/ext actions passed &range.front() and the declared size to the visitor, which memcpy()s size bytes. For std::deque or std::list iterators this reads past the first block or node. Pass a pointer into the input only when the range is contiguous; otherwise copy it first. Fixes msgpack#1224 Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
|
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## cpp_master #1236 +/- ##
==============================================
- Coverage 85.36% 80.10% -5.27%
==============================================
Files 80 80
Lines 5099 5851 +752
Branches 507 648 +141
==============================================
+ Hits 4353 4687 +334
- Misses 746 1164 +418 🚀 New features to boost your workflow:
|
|
Thanks, this fixes #1224 as described. I reproduced the six new cases failing with One thing to be aware of: the O(1) endpoint check in Note that #1237 touches the same lines of |
Fixes #1224
Under
MSGPACK_USE_X3_PARSE, thestr,bin, andextactions ininclude/msgpack/v2/x3_parse.hpppass&range.front()and the declared size to the visitor, andcreate_object_visitorthenmemcpyssizebytes from that pointer. This is valid only when the input iterators point into contiguous storage. Withstd::dequeorstd::listiterators, it reads past the end of the first block or node and copies out-of-bounds bytes into the decoded object.This change adds
app_specific::contiguous()and uses it across all 15str/bin/extcall sites:&*first, keeping zero-copy and reference mode overstd::stringorstd::vectorunchanged.Tests
Added six cases in
test/msgpack_x3_parse.cppthat unpack a 5000-bytestr,bin, andextfromstd::deque<char>andstd::list<char>and compare the result with the input.Built with GCC 13.5, Boost 1.74,
-std=c++17 -fsanitize=address,undefined -DMSGPACK_USE_X3_PARSE:AddressSanitizer: heap-buffer-overflowincreate_object_visitor::visit_str(create_object_visitor.hpp:124) or the matchingbin/extpath.msgpack_x3_parsepass (the 64 existing cases pass both before and after). It also compiles under-std=c++14and-std=c++20with-Wall -Wextraand no warnings fromx3_parse.hpp.Out of scope
Reference mode over a non-contiguous or buffering iterator (#1225) is a separate lifetime problem and is not changed here.
AI-assisted: drafted with an AI coding assistant; reproduced and tested locally before submitting.