OtterMind/Chat2DB · info · IllegalArgumentException

EWKB ends before its declared geometry data

Error message

EWKB ends before its declared geometry data

What it means

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.

Source

Thrown at chat2db-community-server/chat2db-community-plugins/chat2db-community-postgresql/src/main/java/ai/chat2db/plugin/postgresql/value/sub/PostgreSQLGeometryProcessor.java:428

                for (int i = 0; i < Long.BYTES; i++) {
                    value = value << 8 | data[offset + i] & 0xffL;
                }
            } else {
                for (int i = Long.BYTES - 1; i >= 0; i--) {
                    value = value << 8 | data[offset + i] & 0xffL;
                }
            }
            offset += Long.BYTES;
            return value;
        }

        private boolean isExhausted() {
            return offset == data.length;
        }

        private void require(int byteCount) {
            if (byteCount > data.length - offset) {
                throw new IllegalArgumentException("EWKB ends before its declared geometry data");
            }
        }
    }
}

View on GitHub (pinned to 5ee1e990e7)

Solutions

  1. No action required in production — convertJDBCValueByType catches this and returns the raw hex value
  2. Verify the hex string has an even length and matches the declared EWKB structure size
  3. Re-read the column value from the database to rule out transport truncation

Example fix

// before: hex string is truncated — declared structures exceed available bytes
// after: ensure the full EWKB hex is retrieved from the JDBC driver without truncation
Defensive patterns

Strategy: try-catch

Validate before calling

// Already caught in convertJDBCValueByType. For EWKB integrity:
// Verify hex string length matches declared structure sizes.
// An even-length hex string of >= 10 chars passes normalizeHex; content may still be truncated.

Try / catch

try {
    cursor.require(byteCount);
} catch (IllegalArgumentException e) {
    log.debug("EWKB truncated", e);
    return value;
}

Prevention

When it happens

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

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

Related errors


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