OtterMind/Chat2DB · error · Exception

Invalid geometry inputStream - less than five bytes

Error message

Invalid geometry inputStream - less than five bytes

What it means

Error "Invalid geometry inputStream - less than five bytes" thrown in OtterMind/Chat2DB.

Source

Thrown at chat2db-community-server/chat2db-community-plugins/chat2db-community-mysql/src/main/java/ai/chat2db/plugin/mysql/value/sub/MysqlGeometryProcessor.java:43

    @Override
    public String convertJDBCValueByType(JDBCDataValue dataValue) {
        try {
            InputStream inputStream = dataValue.getBinaryStream();
            Geometry dbGeometry = null;
            if (inputStream != null) {
                byte[] buffer = new byte[255];

                int bytesRead = 0;
                ByteArrayOutputStream baos = new ByteArrayOutputStream();
                while ((bytesRead = inputStream.read(buffer)) != -1) {
                    baos.write(buffer, 0, bytesRead);
                }

                byte[] geometryAsBytes = baos.toByteArray();

                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. Ensure the geometry value is a valid WKB/EWKB binary of at least five bytes.
  2. Check that the column actually contains geometry data and was not truncated.

When it happens

Trigger: The MySQL geometry processor received a binary stream shorter than the minimum header size.

Common situations: See trigger scenarios.


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