OtterMind/Chat2DB · warning · Exception

Invalid geometry inputStream - less than five bytes

Error message

Invalid geometry inputStream - less than five bytes

What it means

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.

Source

Thrown at chat2db-community-server/chat2db-community-plugins/chat2db-community-mariadb/src/main/java/ai/chat2db/plugin/mariadb/value/sub/MariaDBGeometryProcessor.java:30

public class MariaDBGeometryProcessor extends DefaultValueProcessor {


    private static final Logger log = LoggerFactory.getLogger(MariaDBGeometryProcessor.class);

    @Override
    public String convertSQLValueByType(SQLDataValue dataValue) {
        return MysqlDmlValueTemplate.wrapGeometry(dataValue.getValue());
    }

    @Override
    public String convertJDBCValueByType(JDBCDataValue dataValue) {
        try {
            Geometry dbGeometry = null;
            byte[] geometryAsBytes = dataValue.getBytes();
            if (geometryAsBytes != null) {
                if (geometryAsBytes.length < 5) {
                    throw new Exception("Invalid geometry inputStream - less than five bytes");
                }
                byte[] sridBytes = new byte[4];
                System.arraycopy(geometryAsBytes, 0, sridBytes, 0, 4);
                boolean bigEndian = (geometryAsBytes[4] == 0x00);

                int srid = 0;
                if (bigEndian) {
                    for (int i = 0; i < sridBytes.length; i++) {
                        srid = (srid << 8) + (sridBytes[i] & 0xff);
                    }
                } else {
                    for (int i = 0; i < sridBytes.length; i++) {
                        srid += (sridBytes[i] & 0xff) << (8 * i);
                    }
                }
                WKBReader wkbReader = new WKBReader();
                byte[] wkb = new byte[geometryAsBytes.length - 4];
                System.arraycopy(geometryAsBytes, 4, wkb, 0, wkb.length);

View on GitHub (pinned to 5ee1e990e7)

Solutions

  1. No caller action is required to avoid a crash; the method already falls back to the raw string value.
  2. To fix the root cause, inspect/repair the stored geometry data so it is valid MariaDB WKB (>= 5 bytes, proper SRID+EWKB).
  3. If you need parsed geometry output, validate the byte length before relying on the parsed result and handle the fallback string.

Example fix

// before: caller calls convertJDBCValueByType and gets a string fallback,
// but the geometry is corrupt in the DB.

// after: validate payload length before parse if you do your own WKB reading
byte[] b = dataValue.getBytes();
if (b == null || b.length < 5) {
    return dataValue.getStringValue(); // mirror the built-in fallback
}
Defensive patterns

Strategy: fallback

Validate before calling

// The library already catches this internally and falls back to getStringValue().
// If you parse MariaDB WKB yourself, guard first:
static boolean isParsableGeometry(byte[] b) {
    return b != null && b.length >= 5;
}

Try / catch

// No caller try/catch required: convertJDBCValueByType catches Exception itself.
// If you replicate the logic, mirror its fallback:
String val;
try {
    val = processor.convertJDBCValueByType(dataValue);
} catch (Exception e) {
    val = dataValue.getStringValue();
}

Prevention

When it happens

Trigger: 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.

Common situations: 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.

Related errors


AI-assisted analysis of OtterMind/Chat2DB@5ee1e990e7 (2026-08-14). Data as JSON: /api/errors/dcb0e0cd5c106cb0. Report an issue: GitHub.