Coverage Report

Created: 2026-04-09 06:10

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/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 "multipart_parser.hpp"
14
15
#include <cstddef>
16
#include <cstdint>
17
#include <string>
18
#include <string_view>
19
20
extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size)
21
14
{
22
14
    if (size < 4)
23
0
    {
24
0
        return 0;
25
0
    }
26
27
    // Use first byte to determine boundary length (1-64 chars)
28
14
    uint8_t boundaryLen =
29
14
        static_cast<uint8_t>((data[0] % 64) + 1); // 1-64 chars
30
14
    size_t offset = 1;
31
32
14
    if (offset + boundaryLen > size)
33
0
    {
34
0
        return 0;
35
0
    }
36
37
14
    std::string boundary(reinterpret_cast<const char*>(data + offset),
38
14
                         boundaryLen);
39
14
    offset += boundaryLen;
40
41
14
    std::string_view body(reinterpret_cast<const char*>(data + offset),
42
14
                          size - offset);
43
44
14
    std::string contentType = "multipart/form-data; boundary=";
45
14
    contentType += boundary;
46
47
14
    MultipartParser parser;
48
14
    parser.parse(contentType, body);
49
50
14
    return 0;
51
14
}