You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
x3 parser: heap out-of-bounds read / information disclosure when unpacking str/bin/ext from a non-contiguous iterator #1224
When built with MSGPACK_USE_X3_PARSE, msgpack::unpack(begin, end) reads out of bounds for str/bin/ext values if begin/end are iterators into a non-contiguous container(std::deque, std::list, …). The x3 grammar hands the visitor &range.front() plus the attacker-declared size, and create_object_visitor::visit_str/bin/ext
(include/msgpack/v2/create_object_visitor.hpp:124) memcpys that many bytes assuming the range is contiguous. The out-of-bounds bytes end up in the decoded object.
Contiguous sources (std::string, std::vector) are fine. boost::spirit::multi_pass (used by example/x3/stream_unpack.cpp) is also fine, so the documented example is not affected — the
problem is specifically node/block iterators.
Steps to reproduce
Build with x3 + ASan and unpack a str larger than one std::deque block from a std::deque:
#include<msgpack.hpp>
#include<deque>
#include<string>
#include<sstream>intmain() {
std::stringstream ss;
msgpack::pack(ss, std::string(600, 'A')); // a str longer than a deque block (512B)
std::string s = ss.str();
std::deque<char> d(s.begin(), s.end());
auto oh = msgpack::unpack(d.begin(), d.end()); // OOB read here
(void)oh;
}
AddressSanitizer: heap-buffer-overflow ... READ of size 600 ...
in create_object_visitor::visit_str (create_object_visitor.hpp:124)
0 bytes after a 512-byte region
A follow-up test shows the over-read bytes are adjacent heap, not the source: a decoded 5000-byte string differs from the input in ~3978 of its bytes (information disclosure into the decoded value).
Expected result
Either a correct decode, or a clean error — no read past the input.
Impact
Out-of-bounds heap read with attacker-controlled length (str/bin/ext size); the decoded object can contain adjacent heap memory (information disclosure). No out-of-bounds write and no reliable crash were observed. Requires MSGPACK_USE_X3_PARSE (non-default) and a non-contiguous input iterator.
Suggested fix
In the x3 str/bin/ext actions, don't assume &range.front() is contiguous for size
bytes: copy the matched range through the iterators into a contiguous buffer before calling the visitor, or static_assert that the iterator is contiguous/random-access so a node container fails to compile.
Activity
AmirWilayah commentedon Nov 17, 2026
ASan Stack trace
AmirWilayah commentedon Nov 17, 2026
Suggest fix
msgpack-cxx-X3NC.patch