{"record":{"id":"aba4abcb656d2348","repo":"prestodb/presto","slug":"invalid-function-argument-aba4ab","errorCode":"INVALID_FUNCTION_ARGUMENT","errorMessage":"Invalid Well-Known Binary (WKB)","messagePattern":"Invalid Well-Known Binary \\(WKB\\)","errorType":"error_code","errorClass":null,"httpStatus":null,"severity":"error","filePath":"presto-base-jdbc/src/main/java/com/facebook/presto/plugin/jdbc/GeometryUtils.java","lineNumber":45,"sourceCode":"\npublic class GeometryUtils\n{\n    private GeometryUtils() {}\n\n    public static Slice getAsText(Slice input)\n    {\n        return utf8Slice(wktFromJtsGeometry(deserialize(input)));\n    }\n\n    public static Slice stGeomFromBinary(Slice input)\n    {\n        requireNonNull(input, \"input is null\");\n        OGCGeometry geometry;\n        try {\n            geometry = fromBinary(input.toByteBuffer().slice());\n        }\n        catch (IllegalArgumentException | IndexOutOfBoundsException e) {\n            throw new PrestoException(INVALID_FUNCTION_ARGUMENT, \"Invalid Well-Known Binary (WKB)\", e);\n        }\n        geometry.setSpatialReference(null);\n        return serialize(geometry);\n    }\n}\n","sourceCodeStart":27,"sourceCodeEnd":51,"githubUrl":"https://github.com/prestodb/presto/blob/55bb57d202de3b926896fa966c2c4a44c779634e/presto-base-jdbc/src/main/java/com/facebook/presto/plugin/jdbc/GeometryUtils.java#L27-L51","documentation":"GeometryUtils.stGeomFromBinary() parses a varbinary as a Well-Known Binary (WKB) geometry via ESRI's fromBinary(). If parsing throws IllegalArgumentException or IndexOutOfBoundsException, it is rethrown as PrestoException(INVALID_FUNCTION_ARGUMENT, \"Invalid Well-Known Binary (WKB)\").","triggerScenarios":"Calling st_geometry_from_binary(blob) (or the connector's geometry functions) with bytes that are not valid WKB: truncated data, wrong endianness/flag byte, or non-geometry binary such as a hash or serialized payload.","commonSituations":"Storing arbitrary binary in a column later parsed as geometry; WKB produced by a tool with a different SRID/encoding convention; data truncated by an upstream ETL step; passing EWKB (PostGIS) with unsupported flags to the strict parser.","solutions":["Validate the input is genuine WKB before parsing (starts with 0x00/0x01 byte-order flag, plausible length)","Use st_is_valid or try the conversion on sample data to locate corrupt rows","Fix upstream producers so only WKB geometry bytes are written to the column","Convert non-standard formats (e.g. PostGIS EWKB) to plain WKB before loading"],"exampleFix":"// before\nSELECT st_geometry_from_binary(payload) FROM raw.shapes; -- payload is not WKB\n// after\nSELECT st_geometry_from_binary(st_as_binary(st_geometry_from_text(wkt))) AS geom\nFROM raw.shapes WHERE is_wkb(payload); -- parse only validated geometry bytes","handlingStrategy":"validation","validationCode":"// Validate a buffer looks like WKB before parsing\nboolean looksLikeWkb(byte[] b) {\n    if (b == null || b.length < 5) return false;\n    byte order = b[0];                      // 0x00 (big-endian) or 0x01 (little-endian)\n    if (order != 0 && order != 1) return false;\n    int type = ByteBuffer.wrap(b, 1, 4).order(order == 0 ? BIG_ENDIAN : LITTLE_ENDIAN).getInt();\n    return type >= 1 && type <= 7;          // point..geometryCollection\n}","typeGuard":null,"tryCatchPattern":"try {\n    geometry = st_geometry_from_binary(blob);\n} catch (PrestoException e) {\n    if (e.getErrorCode() == INVALID_FUNCTION_ARGUMENT.toErrorCode()) {\n        log.warn(\"Skipping non-WKB blob at row {}\", rowId); // filter or quarantine bad rows\n    } else throw e;\n}","preventionTips":["Validate input bytes with st_is_valid / geometry functions before calling WKB parsers in production queries","Ensure ETL writes only WKB produced by st_as_binary into geometry columns","Convert PostGIS EWKB to plain WKB before loading into Presto"],"tags":["geometry","wkb","invalid-argument","spatial"],"backgroundTag":"invalid-wkb-input","analyzedSha":"55bb57d202de3b926896fa966c2c4a44c779634e","analyzedAt":"2026-09-04T12:50:26.162Z","contentChangedAt":"2026-09-04T12:50:26.162Z","schemaVersion":2},"datasetVersion":"2026-09-11T21:17:09.523Z"}