Coverage Report

Created: 2026-06-15 06:15

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
1.32k
{
22
1.32k
    if (size < 4)
23
2
    {
24
2
        return 0;
25
2
    }
26
27
    // Use first byte to determine boundary length (1-64 chars)
28
1.32k
    uint8_t boundaryLen =
29
1.32k
        static_cast<uint8_t>((data[0] % 64) + 1); // 1-64 chars
30
1.32k
    size_t offset = 1;
31
32
1.32k
    if (offset + boundaryLen > size)
33
6
    {
34
6
        return 0;
35
6
    }
36
37
1.31k
    std::string boundary(reinterpret_cast<const char*>(data + offset),
38
1.31k
                         boundaryLen);
39
1.31k
    offset += boundaryLen;
40
41
1.31k
    std::string_view body(reinterpret_cast<const char*>(data + offset),
42
1.31k
                          size - offset);
43
44
1.31k
    std::string contentType = "multipart/form-data; boundary=";
45
1.31k
    contentType += boundary;
46
47
1.31k
    MultipartParser parser;
48
1.31k
    parser.parse(contentType, body);
49
50
1.31k
    return 0;
51
1.32k
}