Coverage Report

Created: 2025-08-24 06:11

/src/bag/fuzzers/bag_extended_fuzzer.cpp
Line
Count
Source (jump to first uncovered line)
1
#include <iostream>
2
#include <iomanip>
3
4
#include <stddef.h>
5
#include <stdint.h>
6
#include <unistd.h>
7
8
#include "bag_dataset.h"
9
10
using BAG::Dataset;
11
12
13
void printLayerDescriptor(
14
        const BAG::LayerDescriptor& descriptor)
15
38
{
16
38
    std::cout << "\t\tchunkSize == " << descriptor.getChunkSize() << '\n';
17
38
    std::cout << "\t\tcompression level == " << descriptor.getCompressionLevel() << '\n';
18
38
    std::cout << "\t\tdata type == " << descriptor.getDataType() << '\n';
19
38
    std::cout << "\t\telement size == " << +descriptor.getElementSize() << '\n';
20
38
    std::cout << "\t\tinternalPath == " << descriptor.getInternalPath() << '\n';
21
38
    std::cout << "\t\tlayer type == " << descriptor.getLayerType() << '\n';
22
23
38
    const auto minMax = descriptor.getMinMax();
24
38
    std::cout << "\t\tmin max == (" << std::get<0>(minMax) << ", " <<
25
38
              std::get<1>(minMax) << ")\n";
26
38
}
27
28
29
25
extern "C" int LLVMFuzzerTestOneInput(const uint8_t *buf, size_t len) {
30
31
25
    char filename[256];
32
25
    snprintf(filename, 255, "/tmp/libfuzzer.%d", getpid());
33
34
    // Save input file to temporary file so that we can read it.
35
25
    FILE *fp = fopen(filename, "wb");
36
25
    if (!fp) {
37
0
        return 0;
38
0
    }
39
25
    fwrite(buf, len, 1, fp);
40
25
    fclose(fp);
41
42
25
    auto pDataset = Dataset::open(filename, BAG_OPEN_READONLY);
43
25
    if (pDataset == NULL) {
44
2
        return EXIT_FAILURE;
45
2
    }
46
47
23
    const auto& descriptor = pDataset->getDescriptor();
48
23
    uint64_t numRows = 0, numCols = 0;
49
23
    std::tie(numRows, numCols) = descriptor.getDims();
50
23
    std::cout << "\trows, columns == " << numRows << ", " << numCols << '\n';
51
52
23
    double minX = 0., minY = 0., maxX = 0., maxY = 0.;
53
23
    std::tie(minX, minY) = pDataset->gridToGeo(0, 0);
54
23
    std::tie(maxX, maxY) = pDataset->gridToGeo(numRows - 1, numCols - 1);
55
56
23
    std::cout << "\tgrid cover (llx, lly), (urx, ury) == (" <<
57
23
              std::setprecision(10) << minX << ", " << minY << "), (" << maxX <<
58
23
              ", " << maxY << ")\n";
59
60
23
    const auto& dims = descriptor.getDims();
61
23
    std::cout << "\tdims == (" << std::get<0>(dims) << ", " <<
62
23
              std::get<1>(dims) << ")\n";
63
64
23
    const auto& gridSpacing = descriptor.getGridSpacing();
65
23
    std::cout << "\tgrid spacing == (" << std::get<0>(gridSpacing) << ", " <<
66
23
              std::get<1>(gridSpacing) << ")\n";
67
68
23
    const auto& origin = descriptor.getOrigin();
69
23
    std::cout << "\torigin == (" << std::get<0>(origin) << ", "
70
23
              << std::get<1>(origin) << ")\n";
71
72
23
    const auto& projCover = descriptor.getProjectedCover();
73
23
    std::cout << "\tprojected cover (llx, lly), (urx, ury) == (" << std::get<0>(projCover) << ", " <<
74
23
              std::get<1>(projCover) << "), (" << std::get<2>(projCover) << ", " <<
75
23
              std::get<3>(projCover) << ")\n";
76
77
23
    std::cout << "\tversion == " << descriptor.getVersion() << '\n';
78
79
23
    std::cout << "\thorizontal reference system ==\n" <<
80
23
              descriptor.getHorizontalReferenceSystem() << "\n\n";
81
82
23
    std::cout << "\tvertical reference system ==\n" << descriptor.getVerticalReferenceSystem() << '\n';
83
84
23
    std::cout << "\nLayers:\n";
85
86
23
    for (const auto& layer : pDataset->getLayers())
87
38
    {
88
38
        auto pDescriptor = layer->getDescriptor();
89
90
38
        std::cout << "\t" << pDescriptor->getName() << " Layer .. id(" <<
91
38
                  pDescriptor->getId() << ")\n";
92
93
38
        printLayerDescriptor(*pDescriptor);
94
38
    }
95
96
23
    const auto& trackingList = pDataset->getTrackingList();
97
23
    std::cout << "\nTracking List:  (" << trackingList.size() << " items)\n";
98
99
23
    size_t itemNum = 0;
100
23
    for (const auto& item : trackingList)
101
0
    {
102
0
        std::cout << "\tTracking list item #" << itemNum++ << '\n';
103
0
        std::cout << "\t\trow == " << item.row << '\n';
104
0
        std::cout << "\t\tcol == " << item.col << '\n';
105
0
        std::cout << "\t\tdepth == " << item.depth << '\n';
106
0
        std::cout << "\t\tuncertainty == " << item.uncertainty << '\n';
107
0
        std::cout << "\t\ttrack_code == " << item.track_code << '\n';
108
0
        std::cout << "\t\tlist_series == " << item.list_series << '\n';
109
0
    }
110
111
23
    pDataset->close();
112
113
23
    return EXIT_SUCCESS;
114
25
}