{"record":{"id":"f0407b0df164a0b9","repo":"OtterMind/Chat2DB","slug":"ewkb-ends-before-its-declared-geometry-data","errorCode":null,"errorMessage":"EWKB ends before its declared geometry data","messagePattern":"EWKB ends before its declared geometry data","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":428,"sourceCode":"                for (int i = 0; i < Long.BYTES; i++) {\n                    value = value << 8 | data[offset + i] & 0xffL;\n                }\n            } else {\n                for (int i = Long.BYTES - 1; i >= 0; i--) {\n                    value = value << 8 | data[offset + i] & 0xffL;\n                }\n            }\n            offset += Long.BYTES;\n            return value;\n        }\n\n        private boolean isExhausted() {\n            return offset == data.length;\n        }\n\n        private void require(int byteCount) {\n            if (byteCount > data.length - offset) {\n                throw new IllegalArgumentException(\"EWKB ends before its declared geometry data\");\n            }\n        }\n    }\n}\n","sourceCodeStart":410,"sourceCodeEnd":433,"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#L410-L433","documentation":"Thrown by WkbCursor.require when a read operation requests more bytes than remain in the EWKB byte array. This means the EWKB declared a structure (point coordinates, count, type word, or SRID) that extends beyond the available data — i.e., the binary is truncated. The require method at line 426 checks byteCount > data.length - offset. It is called by readUnsignedByte, readInt, and readLong throughout the cursor. The exception is caught by convertJDBCValueByType at line 80 and the raw hex value is returned gracefully.","triggerScenarios":"Parsing EWKB whose byte array is shorter than the geometry structures it declares. Any read operation (readUnsignedByte, readInt at line 385, readLong at line 407) that exceeds the remaining buffer triggers this via require.","commonSituations":"Truncated hex string from a JDBC driver; incomplete geometry data from a copy or migration; network-level truncation of a binary column value; hex string with an odd number of characters that was padded.","solutions":["No action required in production — convertJDBCValueByType catches this and returns the raw hex value","Verify the hex string has an even length and matches the declared EWKB structure size","Re-read the column value from the database to rule out transport truncation"],"exampleFix":"// before: hex string is truncated — declared structures exceed available bytes\n// after: ensure the full EWKB hex is retrieved from the JDBC driver without truncation","handlingStrategy":"try-catch","validationCode":"// Already caught in convertJDBCValueByType. For EWKB integrity:\n// Verify hex string length matches declared structure sizes.\n// An even-length hex string of >= 10 chars passes normalizeHex; content may still be truncated.","typeGuard":null,"tryCatchPattern":"try {\n    cursor.require(byteCount);\n} catch (IllegalArgumentException e) {\n    log.debug(\"EWKB truncated\", e);\n    return value;\n}","preventionTips":["Ensure the full EWKB hex string is retrieved without truncation","Verify hex string has an even number of characters","Check JDBC driver behavior for large geometry column reads"],"tags":["postgresql","ewkb","geometry","data-integrity","truncation"],"backgroundTag":null,"analyzedSha":"5ee1e990e73fbcae1969dc554be254fedb3ab888","analyzedAt":"2026-08-14T07:05:03.077Z","schemaVersion":2},"datasetVersion":"2026-08-14T10:17:34.591Z"}