{"record":{"id":"dcb0e0cd5c106cb0","repo":"OtterMind/Chat2DB","slug":"invalid-geometry-inputstream-less-than-five-byte","errorCode":null,"errorMessage":"Invalid geometry inputStream - less than five bytes","messagePattern":"Invalid geometry inputStream - less than five bytes","errorType":"exception","errorClass":"Exception","httpStatus":null,"severity":"warning","filePath":"chat2db-community-server/chat2db-community-plugins/chat2db-community-mariadb/src/main/java/ai/chat2db/plugin/mariadb/value/sub/MariaDBGeometryProcessor.java","lineNumber":30,"sourceCode":"\npublic class MariaDBGeometryProcessor extends DefaultValueProcessor {\n\n\n    private static final Logger log = LoggerFactory.getLogger(MariaDBGeometryProcessor.class);\n\n    @Override\n    public String convertSQLValueByType(SQLDataValue dataValue) {\n        return MysqlDmlValueTemplate.wrapGeometry(dataValue.getValue());\n    }\n\n    @Override\n    public String convertJDBCValueByType(JDBCDataValue dataValue) {\n        try {\n            Geometry dbGeometry = null;\n            byte[] geometryAsBytes = dataValue.getBytes();\n            if (geometryAsBytes != null) {\n                if (geometryAsBytes.length < 5) {\n                    throw new Exception(\"Invalid geometry inputStream - less than five bytes\");\n                }\n                byte[] sridBytes = new byte[4];\n                System.arraycopy(geometryAsBytes, 0, sridBytes, 0, 4);\n                boolean bigEndian = (geometryAsBytes[4] == 0x00);\n\n                int srid = 0;\n                if (bigEndian) {\n                    for (int i = 0; i < sridBytes.length; i++) {\n                        srid = (srid << 8) + (sridBytes[i] & 0xff);\n                    }\n                } else {\n                    for (int i = 0; i < sridBytes.length; i++) {\n                        srid += (sridBytes[i] & 0xff) << (8 * i);\n                    }\n                }\n                WKBReader wkbReader = new WKBReader();\n                byte[] wkb = new byte[geometryAsBytes.length - 4];\n                System.arraycopy(geometryAsBytes, 4, wkb, 0, wkb.length);","sourceCodeStart":12,"sourceCodeEnd":48,"githubUrl":"https://github.com/OtterMind/Chat2DB/blob/5ee1e990e73fbcae1969dc554be254fedb3ab888/chat2db-community-server/chat2db-community-plugins/chat2db-community-mariadb/src/main/java/ai/chat2db/plugin/mariadb/value/sub/MariaDBGeometryProcessor.java#L12-L48","documentation":"Thrown inside MariaDBGeometryProcessor.convertJDBCValueByType when a MariaDB GEOMETRY column returns a non-null byte array shorter than 5 bytes. A MariaDB geometry WKB payload starts with a 4-byte SRID plus a 1-byte byte-order marker, so anything shorter is corrupt/truncated. NOTE: this exception is caught by the surrounding try/catch in the same method (logged at WARN) and the method falls back to dataValue.getStringValue(), so it does not propagate to the caller.","triggerScenarios":"Reading a MariaDB GEOMETRY value whose raw bytes are 1-4 bytes long (truncated SRID, empty-but-not-null payload, or a driver/serialization glitch). The throw is internal; externally you observe a WARN log line and a fallback string value instead of a parsed geometry.","commonSituations":"Corrupt or partially-written geometry data in a row; a JDBC driver or proxy truncating BLOB bytes; an empty geometry placeholder stored as a few bytes; column data written by a non-standard client.","solutions":["No caller action is required to avoid a crash; the method already falls back to the raw string value.","To fix the root cause, inspect/repair the stored geometry data so it is valid MariaDB WKB (>= 5 bytes, proper SRID+EWKB).","If you need parsed geometry output, validate the byte length before relying on the parsed result and handle the fallback string."],"exampleFix":"// before: caller calls convertJDBCValueByType and gets a string fallback,\n// but the geometry is corrupt in the DB.\n\n// after: validate payload length before parse if you do your own WKB reading\nbyte[] b = dataValue.getBytes();\nif (b == null || b.length < 5) {\n    return dataValue.getStringValue(); // mirror the built-in fallback\n}","handlingStrategy":"fallback","validationCode":"// The library already catches this internally and falls back to getStringValue().\n// If you parse MariaDB WKB yourself, guard first:\nstatic boolean isParsableGeometry(byte[] b) {\n    return b != null && b.length >= 5;\n}","typeGuard":null,"tryCatchPattern":"// No caller try/catch required: convertJDBCValueByType catches Exception itself.\n// If you replicate the logic, mirror its fallback:\nString val;\ntry {\n    val = processor.convertJDBCValueByType(dataValue);\n} catch (Exception e) {\n    val = dataValue.getStringValue();\n}","preventionTips":["Treat a WARN 'Invalid geometry inputStream' log as a data-quality signal, not a crash.","Repair corrupt/truncated geometry rows in the database.","Validate WKB payload length (>= 5 bytes) before custom parsing."],"tags":["mariadb","geometry","wkb","jdbc","data-conversion"],"backgroundTag":null,"analyzedSha":"5ee1e990e73fbcae1969dc554be254fedb3ab888","analyzedAt":"2026-08-14T07:05:03.077Z","schemaVersion":2},"datasetVersion":"2026-08-14T10:17:34.591Z"}