Add chunked_decoder_fuzzer and a seed corpus for multipart_parser_fuzzer (#2706)

* Add chunked_decoder_fuzzer and a seed corpus for multipart_parser_fuzzer

* Apply clang-format to chunked_decoder_fuzzer.cc

* Simplify chunked_decoder_fuzzer and tidy the seed corpora

read_content_chunked() only touches the trailers and headers, which
Request and Response share, so decoding into both ran the same code.
Decode into a Response only. Drop the SIZE_MAX limit as well: fuzz
inputs never get near the 100MB default, so both take the same branches.
Adjust the first byte of the chunked seeds to the new selector, and
remove the seed for SIZE_MAX.

Drop the duplicated number prefixes from the multipart seed names, run
both new corpora from the "all" target, and keep the fuzzer rules in
the order of FUZZERS.

---------

Co-authored-by: Sai Viswas Basetti <saiviswasbasettitw@gmail.com>
Co-authored-by: yhirose <yuji.hirose.bug@gmail.com>
This commit is contained in:
authored and GitHub committed 2026-12-02 00:22:05 -05:00
1 parent a4697bd29d
commit 3091751b5d
37 files changed
+227 -1

No files matched your search

+36
View File
@@ -0,0 +1,36 @@
#include <cstdint>
#include "fuzzed_stream.h"
namespace {
void decode(const uint8_t *data, size_t size, size_t payload_max_length) {
FuzzedStream strm(data, size);
httplib::Response res;
httplib::detail::read_content_chunked(
strm, res, payload_max_length,
[](const char *, size_t, uint64_t, uint64_t) { return true; });
}
} // namespace
// The first decode initializes function-local statics, which in a persistent
// fuzzer would otherwise show up as unstable coverage on the first input only.
extern "C" int LLVMFuzzerInitialize(int * /*argc*/, char *** /*argv*/) {
static const char warm_up[] =
"5;ext=1\r\nhello\r\n0\r\nX-Trailer: 1\r\nExpires: 0\r\n\r\n";
decode(reinterpret_cast<const uint8_t *>(warm_up), sizeof(warm_up) - 1, 0);
return 0;
}
extern "C" int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) {
if (size < 2) { return 0; }
// The first byte selects the payload limit, 0 meaning none
static const size_t max_lens[] = {0, 1, 16, 4096,
CPPHTTPLIB_PAYLOAD_MAX_LENGTH};
auto n = sizeof(max_lens) / sizeof(max_lens[0]);
decode(data + 1, size - 1, max_lens[data[0] % n]);
return 0;
}