/****************************************************************************** * * Project: PostGIS * Purpose: Encoded polyline input fuzzer * ****************************************************************************** * Copyright (C) 2026 Darafei Praliaskouski * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License * as published by the Free Software Foundation; either version 2 * of the License, or (at your option) any later version. * ****************************************************************************/ #include #include #include #include extern "C" { #include "geos_stub.h" #include "proj_stub.h" } #include "liblwgeom_fuzzer.hpp" extern "C" int LLVMFuzzerInitialize(int * /*argc*/, char *** /*argv*/) { postgis_lwgeom_fuzzer_initialize(); return 0; } extern "C" int LLVMFuzzerTestOneInput(const uint8_t *buf, size_t len); int LLVMFuzzerTestOneInput(const uint8_t *buf, size_t len) { if (len < 2) return 0; char *polyline = static_cast(malloc(len)); if (polyline == NULL) return 0; memcpy(polyline, buf + 1, len - 1); polyline[len - 1] = '\0'; int precision = buf[0] % 10; if (!POSTGIS_LWGEOM_FUZZER_SETJMP()) { LWGEOM *lwgeom = lwgeom_from_encoded_polyline(polyline, precision); lwgeom_free(lwgeom); } postgis_lwgeom_fuzzer_cleanup_allocations(); free(polyline); return 0; }