/src/multipart_parser_fuzzer.cpp
Line | Count | Source |
1 | | /* Copyright 2026 Google LLC |
2 | | Licensed under the Apache License, Version 2.0 (the "License"); |
3 | | you may not use this file except in compliance with the License. |
4 | | You may obtain a copy of the License at |
5 | | http://www.apache.org/licenses/LICENSE-2.0 |
6 | | Unless required by applicable law or agreed to in writing, software |
7 | | distributed under the License is distributed on an "AS IS" BASIS, |
8 | | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
9 | | See the License for the specific language governing permissions and |
10 | | limitations under the License. |
11 | | */ |
12 | | |
13 | | #include "http_request.hpp" |
14 | | #include "multipart_parser.hpp" |
15 | | |
16 | | #include <cstddef> |
17 | | #include <cstdint> |
18 | | #include <string> |
19 | | #include <string_view> |
20 | | #include <system_error> |
21 | | |
22 | | extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) |
23 | 1.86k | { |
24 | 1.86k | if (size < 4) |
25 | 2 | { |
26 | 2 | return 0; |
27 | 2 | } |
28 | | |
29 | | // Use first two bytes to determine boundary length (1-64 chars) |
30 | 1.86k | uint8_t boundaryLen = |
31 | 1.86k | static_cast<uint8_t>((data[0] % 64) + 1); // 1-64 chars |
32 | 1.86k | size_t offset = 1; |
33 | | |
34 | 1.86k | if (offset + boundaryLen > size) |
35 | 7 | { |
36 | 7 | return 0; |
37 | 7 | } |
38 | | |
39 | 1.86k | std::string boundary(reinterpret_cast<const char*>(data + offset), |
40 | 1.86k | boundaryLen); |
41 | 1.86k | offset += boundaryLen; |
42 | | |
43 | 1.86k | std::string_view body(reinterpret_cast<const char*>(data + offset), |
44 | 1.86k | size - offset); |
45 | | |
46 | 1.86k | std::error_code ec; |
47 | 1.86k | crow::Request req(body, ec); |
48 | | |
49 | 1.86k | std::string contentType = "multipart/form-data; boundary="; |
50 | 1.86k | contentType += boundary; |
51 | 1.86k | req.addHeader("Content-Type", contentType); |
52 | | |
53 | 1.86k | MultipartParser parser; |
54 | 1.86k | parser.parse(req); |
55 | | |
56 | 1.86k | return 0; |
57 | 1.86k | } |