mirror of
https://github.com/yhirose/cpp-httplib.git
synced 2026-12-04 22:08:23 +00:00
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:
37 files changed
+227
-1
No files matched your search
@@ -13,12 +13,14 @@ ZLIB_SUPPORT = -DCPPHTTPLIB_ZLIB_SUPPORT -lz
|
||||
BROTLI_DIR = /usr/local/opt/brotli
|
||||
# BROTLI_SUPPORT = -DCPPHTTPLIB_BROTLI_SUPPORT -I$(BROTLI_DIR)/include -L$(BROTLI_DIR)/lib -lbrotlicommon -lbrotlienc -lbrotlidec
|
||||
|
||||
FUZZERS = server_fuzzer url_parser_fuzzer header_parser_fuzzer client_fuzzer multipart_parser_fuzzer websocket_fuzzer sse_parser_fuzzer server_mount_fuzzer
|
||||
FUZZERS = server_fuzzer url_parser_fuzzer header_parser_fuzzer client_fuzzer multipart_parser_fuzzer websocket_fuzzer sse_parser_fuzzer server_mount_fuzzer chunked_decoder_fuzzer
|
||||
|
||||
# Runs all the tests and also fuzz tests against seed corpus.
|
||||
all : $(FUZZERS)
|
||||
./server_fuzzer corpus/*
|
||||
./server_mount_fuzzer corpus_mount/*
|
||||
./multipart_parser_fuzzer corpus_multipart/*
|
||||
./chunked_decoder_fuzzer corpus_chunked/*
|
||||
|
||||
# Fuzz target, so that you can choose which $(LIB_FUZZING_ENGINE) to use.
|
||||
server_fuzzer : server_fuzzer.cc fuzzed_stream.h ../../httplib.h
|
||||
@@ -38,6 +40,7 @@ url_parser_fuzzer : url_parser_fuzzer.cc ../../httplib.h
|
||||
|
||||
multipart_parser_fuzzer : multipart_parser_fuzzer.cc ../../httplib.h
|
||||
$(CXX) $(CXXFLAGS) -o $@ $< $(ZLIB_SUPPORT) $(LIB_FUZZING_ENGINE) -pthread -lanl
|
||||
zip -q -r multipart_parser_fuzzer_seed_corpus.zip corpus_multipart
|
||||
|
||||
websocket_fuzzer : websocket_fuzzer.cc ../../httplib.h
|
||||
$(CXX) $(CXXFLAGS) -o $@ $< $(ZLIB_SUPPORT) $(LIB_FUZZING_ENGINE) -pthread -lanl
|
||||
@@ -49,5 +52,9 @@ server_mount_fuzzer : server_mount_fuzzer.cc fuzzed_stream.h ../../httplib.h
|
||||
$(CXX) $(CXXFLAGS) -o $@ $< $(ZLIB_SUPPORT) $(LIB_FUZZING_ENGINE) -pthread -lanl
|
||||
zip -q -r server_mount_fuzzer_seed_corpus.zip corpus_mount
|
||||
|
||||
chunked_decoder_fuzzer : chunked_decoder_fuzzer.cc fuzzed_stream.h ../../httplib.h
|
||||
$(CXX) $(CXXFLAGS) -o $@ $< $(ZLIB_SUPPORT) $(LIB_FUZZING_ENGINE) -pthread -lanl
|
||||
zip -q -r chunked_decoder_fuzzer_seed_corpus.zip corpus_chunked
|
||||
|
||||
clean:
|
||||
rm -f server_fuzzer pem *.0 *.o *.1 *.srl *.zip
|
||||
@@ -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;
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
crlf="\x0d\x0a"
|
||||
last_chunk="0\x0d\x0a\x0d\x0a"
|
||||
ext=";"
|
||||
ext_kv=";name=value"
|
||||
ext_quoted=";name=\"a;b\""
|
||||
hex_max="ffffffffffffffff"
|
||||
hex_over="10000000000000000"
|
||||
trailer="X-Trailer: 1\x0d\x0a"
|
||||
expires="Expires: 0\x0d\x0a"
|
||||
Binary file not shown.
Binary file not shown.
@@ -0,0 +1,4 @@
|
||||
10
|
||||
0123456789abcdef
|
||||
0
|
||||
|
||||
@@ -0,0 +1,6 @@
|
||||
10
|
||||
0123456789abcdef
|
||||
1
|
||||
X
|
||||
0
|
||||
|
||||
@@ -0,0 +1,4 @@
|
||||
5
|
||||
hello
|
||||
0
|
||||
|
||||
@@ -0,0 +1,4 @@
|
||||
5
|
||||
hello
|
||||
0
|
||||
|
||||
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@@ -0,0 +1,5 @@
|
||||
1234567890123456--1234567890123456
|
||||
Content-Disposition: form-data; name="f"
|
||||
|
||||
v
|
||||
--1234567890123456--
|
||||
Binary file not shown.
@@ -0,0 +1,5 @@
|
||||
BOUND--BOUND
|
||||
Content-Disposition: form-data; name="a"
|
||||
|
||||
text contains --BOUND here
|
||||
--BOUND--
|
||||
@@ -0,0 +1,13 @@
|
||||
XYZ123--XYZ123
|
||||
Content-Disposition: form-data; name="t"
|
||||
|
||||
--XYZ123 not after CRLF
|
||||
|
||||
--XYZ12
|
||||
|
||||
-XYZ123
|
||||
|
||||
--xyz123
|
||||
|
||||
--XYZ_123␍ tail
|
||||
--XYZ123--
|
||||
@@ -0,0 +1,13 @@
|
||||
cdBad--cdBad
|
||||
Content-Disposition: form-data; filename="noname.txt"
|
||||
|
||||
missing name
|
||||
--cdBad
|
||||
Content-Disposition: form-data; name="x"; filename*=ISO-8859-1''abc
|
||||
|
||||
bad charset
|
||||
--cdBad
|
||||
Bad Header Without Colon
|
||||
|
||||
z
|
||||
--cdBad--
|
||||
@@ -0,0 +1,22 @@
|
||||
cdVar--cdVar
|
||||
content-disposition:FORM-DATA;name=bare
|
||||
|
||||
1
|
||||
--cdVar
|
||||
Content-Disposition: form-data; name="semi;colon"; filename="a\"b.txt"
|
||||
|
||||
2
|
||||
--cdVar
|
||||
Content-Disposition: form-data; name="u"; filename="x.txt"; filename*=UTF-8''%E2%82%AC%20rates.txt
|
||||
|
||||
3
|
||||
--cdVar
|
||||
Content-Disposition: form-data; name="dup"; name="dup"; name="other"
|
||||
|
||||
4
|
||||
--cdVar
|
||||
Content-Disposition: attachment; name="ignored"
|
||||
CONTENT-TYPE: text/html
|
||||
|
||||
5
|
||||
--cdVar--
|
||||
@@ -0,0 +1,11 @@
|
||||
empty--empty
|
||||
|
||||
|
||||
--empty
|
||||
Content-Disposition: form-data; name="e"
|
||||
|
||||
|
||||
--empty
|
||||
|
||||
|
||||
--empty--
|
||||
@@ -0,0 +1,6 @@
|
||||
BOUND--BOUND
|
||||
Content-Disposition: form-data; name="a"
|
||||
X-Custom: test
|
||||
|
||||
val
|
||||
--BOUND--
|
||||
Binary file not shown.
@@ -0,0 +1,9 @@
|
||||
pad--pad
|
||||
Content-Disposition: form-data; name="a"
|
||||
|
||||
ok
|
||||
--pad
|
||||
Content-Disposition: form-data; name="b"
|
||||
|
||||
x
|
||||
--pad--
|
||||
@@ -0,0 +1,6 @@
|
||||
BOUND
|
||||
--BOUND
|
||||
Content-Disposition: form-data; name="a"
|
||||
|
||||
val
|
||||
--BOUND--
|
||||
@@ -0,0 +1,9 @@
|
||||
unclosed--unclosed
|
||||
Content-Disposition: form-data; name="a"
|
||||
|
||||
first
|
||||
--unclosed
|
||||
Content-Disposition: form-data; name="b"
|
||||
|
||||
truncated content with no final delimiter
|
||||
--unclo
|
||||
@@ -0,0 +1,5 @@
|
||||
BOUND--BOUND
|
||||
Content-Disposition: form-data; name="a"
|
||||
|
||||
val
|
||||
--BOUND--
|
||||
@@ -0,0 +1,4 @@
|
||||
nocrlf--nocrlfContent-Disposition: form-data; name="x"
|
||||
|
||||
data
|
||||
--nocrlf--
|
||||
@@ -0,0 +1,4 @@
|
||||
hdrEnd--hdrEnd
|
||||
Content-Disposition: form-data; name="h"
|
||||
Content-Type: text/plain
|
||||
content right after headers--hdrEnd--
|
||||
@@ -0,0 +1,9 @@
|
||||
BOUND--BOUND
|
||||
Content-Disposition: form-data; name="a"
|
||||
|
||||
1
|
||||
--BOUND
|
||||
Content-Disposition: form-data; name="b"
|
||||
|
||||
2
|
||||
--BOUND--
|
||||
@@ -0,0 +1,5 @@
|
||||
BOUND--BOUND
|
||||
Content-Type: text/plain
|
||||
|
||||
orphaned data
|
||||
--BOUND--
|
||||
@@ -0,0 +1,15 @@
|
||||
sev3ral--sev3ral
|
||||
Content-Disposition: form-data; name="a"
|
||||
|
||||
alpha
|
||||
--sev3ral
|
||||
Content-Disposition: form-data; name="b"
|
||||
|
||||
bravo
|
||||
second line
|
||||
--sev3ral
|
||||
Content-Disposition: form-data; name="c"
|
||||
Content-Type: application/json
|
||||
|
||||
{"k":[1,2,3]}
|
||||
--sev3ral--
|
||||
@@ -0,0 +1,5 @@
|
||||
AaB03x--AaB03x
|
||||
Content-Disposition: form-data; name="field1"
|
||||
|
||||
value1
|
||||
--AaB03x--
|
||||
@@ -0,0 +1,5 @@
|
||||
BOUND--BOUND
|
||||
Content-Disposition: form-data; name="user"
|
||||
|
||||
Alice
|
||||
--BOUND--
|
||||
@@ -0,0 +1,5 @@
|
||||
BOUND--BOUND
|
||||
Content-Disposition : form-data ; name = "a"
|
||||
|
||||
val
|
||||
--BOUND--
|
||||
Reference in new issue
Block a user