{"record":{"id":"c40734f30c16d6af","repo":"OtterMind/Chat2DB","slug":"unsupported-ewkb-byte-order","errorCode":null,"errorMessage":"Unsupported EWKB byte order","messagePattern":"Unsupported EWKB byte order","errorType":"validation","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"info","filePath":"chat2db-community-server/chat2db-community-plugins/chat2db-community-postgresql/src/main/java/ai/chat2db/plugin/postgresql/value/sub/PostgreSQLGeometryProcessor.java","lineNumber":307,"sourceCode":"    }\n\n    private int readCount(WkbCursor cursor, ByteOrder byteOrder) {\n        int count = cursor.readInt(byteOrder);\n        if (count < 0) {\n            throw new IllegalArgumentException(\"EWKB contains a negative element count\");\n        }\n        return count;\n    }\n\n    private ByteOrder readByteOrder(WkbCursor cursor) {\n        int byteOrder = cursor.readUnsignedByte();\n        if (byteOrder == 0) {\n            return ByteOrder.BIG_ENDIAN;\n        }\n        if (byteOrder == 1) {\n            return ByteOrder.LITTLE_ENDIAN;\n        }\n        throw new IllegalArgumentException(\"Unsupported EWKB byte order\");\n    }\n\n    private String removeTypeParenthesisSpace(String wkt) {\n        int openParenthesis = wkt.indexOf('(');\n        if (openParenthesis > 0 && wkt.charAt(openParenthesis - 1) == ' ') {\n            return wkt.substring(0, openParenthesis - 1) + wkt.substring(openParenthesis);\n        }\n        return wkt;\n    }\n\n    private record WkbHeader(int baseType, boolean hasZ, boolean hasMeasure, Integer srid) {\n    }\n\n    private static final class BoundedStringWriter extends Writer {\n\n        private final StringBuilder value = new StringBuilder();\n        private final int maxChars;\n","sourceCodeStart":289,"sourceCodeEnd":325,"githubUrl":"https://github.com/OtterMind/Chat2DB/blob/5ee1e990e73fbcae1969dc554be254fedb3ab888/chat2db-community-server/chat2db-community-plugins/chat2db-community-postgresql/src/main/java/ai/chat2db/plugin/postgresql/value/sub/PostgreSQLGeometryProcessor.java#L289-L325","documentation":"Thrown by PostgreSQLGeometryProcessor.readByteOrder when the first byte of a geometry sub-structure in EWKB is neither 0 (big-endian) nor 1 (little-endian). The WKB/EWKB specification allows only these two byte-order markers. This method is called at the start of every geometry parsing in inspectGeometry (line 176). The exception is caught by convertJDBCValueByType at line 80 and the raw hex value is returned gracefully.","triggerScenarios":"Parsing EWKB where any geometry sub-structure's first byte is not 0x00 or 0x01. readByteOrder at line 299 reads an unsigned byte and throws for any other value.","commonSituations":"Corrupt or truncated binary data where the byte-order byte is damaged; data from a non-compliant EWKB producer; hex string with a wrong prefix that passed normalizeHex validation but has corrupt content; endianness of the entire stream is wrong causing byte misalignment.","solutions":["No action required in production — convertJDBCValueByType catches this and returns the raw hex value","Verify the hex string starts with 00 or 01 for each geometry sub-structure","Check for byte alignment issues caused by a wrong top-level byte order"],"exampleFix":"// before: byte-order byte is neither 0x00 nor 0x01 (corrupt EWKB)\n// after: ensure each geometry's first byte is 00 (big-endian) or 01 (little-endian)","handlingStrategy":"try-catch","validationCode":"// Already caught in convertJDBCValueByType. For EWKB integrity:\n// Each geometry sub-structure must start with byte 0x00 (big-endian) or 0x01 (little-endian).","typeGuard":null,"tryCatchPattern":"try {\n    ByteOrder bo = readByteOrder(cursor);\n} catch (IllegalArgumentException e) {\n    log.debug(\"EWKB unsupported byte order\", e);\n    return value;\n}","preventionTips":["Verify the EWKB hex starts with 00 or 01 at each geometry boundary","Check for byte-alignment issues if the top-level byte order is wrong","Re-import geometry data from a trusted source if the binary is corrupt"],"tags":["postgresql","ewkb","geometry","data-integrity","validation"],"backgroundTag":null,"analyzedSha":"5ee1e990e73fbcae1969dc554be254fedb3ab888","analyzedAt":"2026-08-14T07:05:03.077Z","schemaVersion":2},"datasetVersion":"2026-08-14T10:17:34.591Z"}