fuzz: check http_request body matches framing #35759

pull Ameen-Alam wants to merge 1 commits into bitcoin:master from Ameen-Alam:fuzz-http-request-body-assert changing 1 files +19 −1
  1. Ameen-Alam commented at 9:42 PM on July 20, 2026: none

    The http_request target asserted that ReadBody() returns an empty string. That held for the libevent-based http_libevent::HTTPRequest, where the harness only parsed the request line and headers and never populated a body. Commit 9c20859b5f (PR #35182) replaced libevent with http_bitcoin::HTTPRequest, and the target was switched over in e427c227fa; its LoadBody() now decodes Content-Length and chunked bodies per RFC 9112, so any fully-parsed request carrying a body trips the stale assertion (e.g. "POST / HTTP/1.1\r\nContent-Length: 3\r\n\r\nabc").

    Replace the emptiness check with a framing-consistency check that mirrors LoadBody()'s own branch logic: a chunked body is bounded by MAX_BODY_SIZE, a Content-Length body is exactly that many bytes, and a request with neither framing header has no body. This strengthens the target instead of dropping the assertion.

    Steps to reproduce (old assertion): Build the fuzz binary and pass this input as a file to the http_request target: POST / HTTP/1.1\r\nContent-Length: 3\r\n\r\nabctest/fuzz/http_request.cpp:49: Assertion 'body.empty()' failed

    Testing the fix: Ran the updated target ~16 min under libFuzzer with ASAN/UBSAN (14.2M execs, no crashes), plus targeted inputs for each branch: Content-Length body, chunked, Transfer-Encoding: identity + Content-Length, no framing headers, and Content-Length: 0. Happy to contribute the repro input to qa-assets as a follow-up.

  2. fuzz: check http_request body matches framing
    The http_request target asserted that ReadBody() returns an empty
    string. That held for the libevent-based http_libevent::HTTPRequest,
    where the harness only parsed the request line and headers and never
    populated a body. Commit 9c20859b5f (PR #35182) replaced libevent with
    http_bitcoin::HTTPRequest, and the target was switched over in
    e427c227fa; its LoadBody() now decodes Content-Length and chunked
    bodies per RFC 9112, so any fully-parsed request carrying a body trips
    the stale assertion (e.g. "POST / HTTP/1.1\r\nContent-Length: 3\r\n\r\nabc").
    
    Replace the emptiness check with a framing-consistency check that
    mirrors LoadBody()'s own branch logic: a chunked body is bounded by
    MAX_BODY_SIZE, a Content-Length body is exactly that many bytes, and a
    request with neither framing header has no body. This strengthens the
    target instead of dropping the assertion.
    7502b9ddba
  3. DrahtBot added the label Fuzzing on Jul 20, 2026
  4. DrahtBot commented at 9:42 PM on July 20, 2026: contributor

    <!--e57a25ab6845829454e8d69fc972939a-->

    The following sections might be updated with supplementary metadata relevant to reviewers and maintainers.

    <!--006a51241073e994b41acfe9ec718e94-->

    Code Coverage & Benchmarks

    For details see: https://corecheck.dev/bitcoin/bitcoin/pulls/35759.

    <!--021abf342d371248e50ceaed478a90ca-->

    Reviews

    See the guideline and AI policy for information on the review process. A summary of reviews will appear here.

    <!--5faf32d7da4f0f540f40219e4f7537a3-->

  5. pinheadmz commented at 10:13 PM on July 20, 2026: member

    concept ack on improving the http fuzz test but I'd like to wait for #35735 which I think might also fix this same issue or otherwise require a fuzz test change.

    My assumption in #35182 was the readbody assertion was safe because of the unlikelihood that fuzz data produces a valid HTTP request. I fuzzed for days without a crash (https://github.com/bitcoin-core/qa-assets/pull/280)

    But I think the authors intention here is correct, the assertion was safe not because of luck but because of libevent's architecture.

  6. Ameen-Alam commented at 10:22 PM on July 20, 2026: none

    Thanks Mr. Matthew Zipkin, that makes sense. I am happy to wait for #35735, then rebase and adapt this change based on the LoadBody semantics that land there. The reproducer currently triggers deterministically on master, so I will rerun it against #35735 to check whether a body assertion is still needed. I can also share the test results on that PR.


github-metadata-mirror

This is a metadata mirror of the GitHub repository bitcoin/bitcoin. This site is not affiliated with GitHub. Content is generated from a GitHub metadata backup.
generated: 2026-07-22 06:50 UTC

This site is hosted by @0xB10C
More mirrored repositories can be found on mirror.b10c.me