Details
Description
The SRID-prefixed internal encoding with WKB byte-order discriminator 2 is interpreted as POINT(1 2) and persisted in a GEOMETRY NOT NULL column, while the equivalent external WKB passed to ST_GeomFromWKB is rejected. This was reproduced with MariaDB 12.3.3 on Linux/amd64.
Reproducer
Execute the following SQL:
-- Oracle:
|
-- valid_internal_wkb = POINT(1 2)
|
-- invalid_internal_wkb IS NULL = 1
|
-- invalid_external_wkb IS NULL = 1
|
-- The second and third expressions contain the same invalid byte-order value
|
-- (2); they differ only by MariaDB's four-byte internal SRID prefix.
|
SELECT
|
ST_AsText(0x000000000101000000000000000000F03F0000000000000040)
|
AS valid_internal_wkb, |
ST_AsText(0x000000000201000000000000000000F03F0000000000000040) IS NULL |
AS invalid_internal_wkb_is_null, |
ST_GeomFromWKB(0x0201000000000000000000F03F0000000000000040) IS NULL |
AS invalid_external_wkb_is_null; |
 |
DROP DATABASE IF EXISTS wkb_bytes; |
CREATE DATABASE wkb_bytes; |
USE wkb_bytes; |
CREATE TABLE wkb_bytes (g GEOMETRY NOT NULL); |
INSERT INTO wkb_bytes |
VALUES (0x000000000201000000000000000000F03F0000000000000040); |
SELECT COUNT(*) AS invalid_rows_persisted, |
MIN(ST_AsText(g)) AS interpreted_value |
FROM wkb_bytes; |
DROP DATABASE wkb_bytes; |
The client output is:
POINT(1 2) 0 1
|
1 POINT(1 2)
|
The first row contains valid_internal_wkb, invalid_internal_wkb_is_null, and invalid_external_wkb_is_null, respectively. The 0 shows that the invalid internal encoding did not return NULL, whereas the equivalent external WKB did. The second row shows that one malformed value was persisted and interpreted as POINT(1 2).
Every serialized-geometry entry path should reject a WKB byte-order discriminator other than 0 (wkb_xdr) or 1 (wkb_ndr) before interpreting or storing the value. Therefore, invalid_internal_wkb_is_null should be 1, and the malformed value should not produce a persistent row.
This occurs when SRID-prefixed internal geometry bytes with an invalid WKB byte-order discriminator are interpreted or stored.
Attachments
Issue Links
- relates to
-
MDEV-27838 Add handling of correct byte order in WKB geometries
-
- Open
-