OtterMind/Chat2DB · info · IllegalArgumentException
Unsupported EWKB byte order
Error message
Unsupported EWKB byte order
What it means
Thrown by PostgreSQLGeometryProcessor.readByteOrder when the first byte of a geometry sub-structure in EWKB is neither 0 (big-endian) nor 1 (little-endian). The WKB/EWKB specification allows only these two byte-order markers. This method is called at the start of every geometry parsing in inspectGeometry (line 176). 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:307
}
private int readCount(WkbCursor cursor, ByteOrder byteOrder) {
int count = cursor.readInt(byteOrder);
if (count < 0) {
throw new IllegalArgumentException("EWKB contains a negative element count");
}
return count;
}
private ByteOrder readByteOrder(WkbCursor cursor) {
int byteOrder = cursor.readUnsignedByte();
if (byteOrder == 0) {
return ByteOrder.BIG_ENDIAN;
}
if (byteOrder == 1) {
return ByteOrder.LITTLE_ENDIAN;
}
throw new IllegalArgumentException("Unsupported EWKB byte order");
}
private String removeTypeParenthesisSpace(String wkt) {
int openParenthesis = wkt.indexOf('(');
if (openParenthesis > 0 && wkt.charAt(openParenthesis - 1) == ' ') {
return wkt.substring(0, openParenthesis - 1) + wkt.substring(openParenthesis);
}
return wkt;
}
private record WkbHeader(int baseType, boolean hasZ, boolean hasMeasure, Integer srid) {
}
private static final class BoundedStringWriter extends Writer {
private final StringBuilder value = new StringBuilder();
private final int maxChars;
View on GitHub (pinned to 5ee1e990e7)
Solutions
- No action required in production — convertJDBCValueByType catches this and returns the raw hex value
- Verify the hex string starts with 00 or 01 for each geometry sub-structure
- Check for byte alignment issues caused by a wrong top-level byte order
Example fix
// before: byte-order byte is neither 0x00 nor 0x01 (corrupt EWKB) // after: ensure each geometry's first byte is 00 (big-endian) or 01 (little-endian)
Defensive patterns
Strategy: try-catch
Validate before calling
// Already caught in convertJDBCValueByType. For EWKB integrity: // Each geometry sub-structure must start with byte 0x00 (big-endian) or 0x01 (little-endian).
Try / catch
try {
ByteOrder bo = readByteOrder(cursor);
} catch (IllegalArgumentException e) {
log.debug("EWKB unsupported byte order", e);
return value;
} Prevention
- Verify the EWKB hex starts with 00 or 01 at each geometry boundary
- Check for byte-alignment issues if the top-level byte order is wrong
- Re-import geometry data from a trusted source if the binary is corrupt
When it happens
Trigger: Parsing EWKB where any geometry sub-structure's first byte is not 0x00 or 0x01. readByteOrder at line 299 reads an unsigned byte and throws for any other value.
Common situations: Corrupt or truncated binary data where the byte-order byte is damaged; data from a non-compliant EWKB producer; hex string with a wrong prefix that passed normalizeHex validation but has corrupt content; endianness of the entire stream is wrong causing byte misalignment.
Related errors
- EWKB coordinate is not finite
- EWKB contains a negative element count
- EWKB line string must be empty or contain at least two coord
- EWKB linear ring must contain at least four coordinates
- EWKB linear ring is not closed
AI-assisted analysis of OtterMind/Chat2DB@5ee1e990e7 (2026-08-14).
Data as JSON: /api/errors/c40734f30c16d6af.
Report an issue: GitHub.