Skip to content

OSS-Fuzz: Add new fuzzer/corpus/dict targets stream unpacking operations - #1214

Open
arthurscchan wants to merge 1 commit into
msgpack:cpp_masterfrom
arthurscchan:msgpack-c-unpacker-stream
Open

arthurscchan wants to merge 1 commit into
msgpack:cpp_masterfrom
arthurscchan:msgpack-c-unpacker-stream

Conversation

@arthurscchan

Copy link
Copy Markdown

This PR adds a new OSS-Fuzz fuzzer with corpus/dict targets stream unpacking operations, together with google/oss-fuzz#16492 to enable a new fuzzer, aiming to improve the overall fuzzing coverage and effectiveness for project msgpack-c.

Signed-off-by: Arthur Chan <arthur.chan@adalogics.com>
@arthurscchan
arthurscchan force-pushed the msgpack-c-unpacker-stream branch from d2b630a to 8224f52 Compare November 20, 2026 07:35
@codecov-commenter

Copy link
Copy Markdown

⚠️ Please install the 'codecov app svg image' to ensure uploads and comments are reliably processed by Codecov.

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 79.96%. Comparing base (39cc081) to head (8224f52).
⚠️ Report is 44 commits behind head on cpp_master.
❗ Your organization needs to install the Codecov GitHub app to enable full functionality.

Additional details and impacted files
@@              Coverage Diff               @@
##           cpp_master    #1214      +/-   ##
==============================================
- Coverage       85.36%   79.96%   -5.41%     
==============================================
  Files              80       80              
  Lines            5099     5824     +725     
  Branches          507      638     +131     
==============================================
+ Hits             4353     4657     +304     
- Misses            746     1167     +421     
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@redboltz

Copy link
Copy Markdown
Contributor

Thank you. The issues shared by the four fuzzing PRs (dictionary format, duplicated corpora, the "report 20261108" references, CI compilation) are summarized in #1212, so I won't repeat them here. The dictionary format fix is required for this PR too.

Required: the legacy path must call reset() after a successful execute()

The legacy_path branch does:

while (upk.execute() && objects < kMaxObjects) {
    sink_u64(static_cast<std::size_t>(upk.data().type));
    ++objects;
    std::unique_ptr<msgpack::zone> z(upk.release_zone());
    upk.reset_zone();
}

After execute() returns true, the unpacker must be reset with reset() before the next execute(). That is what next() does internally, and the parser does not return its state to "expect a header" on its own. reset_zone() only clears the zone (and after release_zone() the unpacker already holds a fresh zone, so that call is a no-op here).

Because of this, the second execute() runs with stale parser state. The three-byte stream c4 00 00 (an empty bin8 followed by fixint 0) is enough to trigger it:

const char in[] = "\xc4\x00\x00";
msgpack::v1::unpacker u;
u.reserve_buffer(3); std::memcpy(u.buffer(), in, 3); u.buffer_consumed(3);
while (u.execute()) {
    std::unique_ptr<msgpack::zone> z(u.release_zone());
    u.reset_zone();            // wrong: should be u.reset();
}

With reset_zone() the loop never terminates, and UBSan reports a pointer-arithmetic overflow at v1/unpack.hpp:577 (m_current += m_trail - 1 with m_trail == 0). With reset() the same input yields two objects and finishes normally. Once this harness is on OSS-Fuzz, this will show up immediately as a false positive against the library, so please change the call to upk.reset() before this is merged.

This is the same contract as the C API: msgpack_unpacker_execute() requires msgpack_unpacker_reset() before the next call, and msgpack_unpacker_next() / msgpack::unpacker::next() call it internally. The library is behaving as designed here, so the fix belongs in the harness.

Suggestion (non-blocking): also cover the default unpacker

This harness only exercises msgpack::v1::unpacker. The default msgpack::unpacker (the v2 parser) is what applications use, and its streaming path is not reached here. Adding one more fuzz-chosen mode bit that switches between msgpack::v1::unpacker and msgpack::unpacker would make the harness considerably more valuable at almost no cost.

Request

Please rebase this PR onto the current cpp_master (rebase, not merge) when you update it. cpp_master has moved since the series was opened.

This branch has not been deployed

No deployments
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