Coverage Report

Created: 2026-03-02 06:14

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/uWebSockets/fuzzing/MultipartParser.cpp
Line
Count
Source
1
/* This is a fuzz test of the multipart parser */
2
3
#define WIN32_EXPORT
4
5
#include <cstdio>
6
#include <string>
7
#include <cstdlib>
8
9
#include "../src/Multipart.h"
10
11
1.47k
extern "C" int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) {
12
13
1.47k
    if (!size) {
14
0
        return 0;
15
0
    }
16
17
1.47k
    char *mutableMemory = (char *) malloc(size);
18
1.47k
    memcpy(mutableMemory, data, size);
19
20
    /* First byte determines how long contentType is */
21
1.47k
    unsigned char contentTypeLength = data[0];
22
1.47k
    size--;
23
24
1.47k
    std::string_view contentType((char *) mutableMemory + 1, std::min<size_t>(contentTypeLength, size));
25
1.47k
    size -= contentType.length();
26
27
1.47k
    std::string_view body((char *) mutableMemory + 1 + contentType.length(), size);
28
29
1.47k
    uWS::MultipartParser mp(contentType);
30
1.47k
    if (mp.isValid()) {
31
1.31k
        mp.setBody(body);
32
33
1.31k
        std::pair<std::string_view, std::string_view> headers[10];
34
35
3.94k
        while (true) {
36
3.94k
            std::optional<std::string_view> optionalPart = mp.getNextPart(headers);
37
3.94k
            if (!optionalPart.has_value()) {
38
1.31k
                break;
39
1.31k
            }
40
41
2.62k
            std::string_view part = optionalPart.value();
42
43
8.17k
            for (int i = 0; headers[i].first.length(); i++) {
44
                /* We care about content-type and content-disposition */
45
5.55k
                if (headers[i].first == "content-disposition") {
46
                    /* Parse the parameters */
47
4.39k
                    uWS::ParameterParser pp(headers[i].second);
48
81.4k
                    while (true) {
49
81.4k
                        auto [key, value] = pp.getKeyValue();
50
81.4k
                        if (!key.length()) {
51
4.39k
                            break;
52
4.39k
                        }
53
81.4k
                    }
54
4.39k
                }
55
5.55k
            }
56
2.62k
        }
57
1.31k
    }
58
59
1.47k
    free(mutableMemory);
60
1.47k
    return 0;
61
1.47k
}
62