Coverage Report

Created: 2026-09-03 06:43

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/postgis/fuzzers/wkt_import_fuzzer.cpp
Line
Count
Source
1
/******************************************************************************
2
 *
3
 * Project:  PostGIS
4
 * Purpose:  Fuzzer
5
 * Author:   Even Rouault, even.rouault at spatialys.com
6
 *
7
 ******************************************************************************
8
 * Copyright (c) 2017, Even Rouault <even.rouault at spatialys.com>
9
 *
10
 * Permission is hereby granted, free of charge, to any person obtaining a
11
 * copy of this software and associated documentation files (the "Software"),
12
 * to deal in the Software without restriction, including without limitation
13
 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
14
 * and/or sell copies of the Software, and to permit persons to whom the
15
 * Software is furnished to do so, subject to the following conditions:
16
 *
17
 * The above copyright notice and this permission notice shall be included
18
 * in all copies or substantial portions of the Software.
19
 *
20
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
21
 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
22
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
23
 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
24
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
25
 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
26
 * DEALINGS IN THE SOFTWARE.
27
 ****************************************************************************/
28
29
#include <stddef.h>
30
#include <stdint.h>
31
#include <stdlib.h>
32
#include <string.h>
33
34
extern "C" {
35
#include "geos_stub.h"
36
#include "proj_stub.h"
37
}
38
39
#include "liblwgeom_fuzzer.hpp"
40
41
extern "C" int
42
LLVMFuzzerInitialize(int * /*argc*/, char *** /*argv*/)
43
18
{
44
18
  postgis_lwgeom_fuzzer_initialize();
45
18
  return 0;
46
18
}
47
48
extern "C" int LLVMFuzzerTestOneInput(const uint8_t *buf, size_t len);
49
50
int LLVMFuzzerTestOneInput(const uint8_t *buf, size_t len)
51
2.70k
{
52
2.70k
  char *pszWKT = static_cast<char *>(malloc(len + 1));
53
2.70k
  if (pszWKT == NULL)
54
0
    return 0;
55
56
2.70k
  memcpy(pszWKT, buf, len);
57
2.70k
  pszWKT[len] = '\0';
58
2.70k
  if (!POSTGIS_LWGEOM_FUZZER_SETJMP())
59
2.70k
  {
60
2.70k
    LWGEOM *lwgeom = lwgeom_from_wkt(pszWKT, LW_PARSER_CHECK_NONE);
61
2.70k
    lwgeom_free(lwgeom);
62
2.70k
  }
63
2.70k
  postgis_lwgeom_fuzzer_cleanup_allocations();
64
2.70k
  free(pszWKT);
65
2.70k
  return 0;
66
2.70k
}