Bug #12839 Endian Support on WKB is absurd
Submitted: 26 Aug 2005 17:35 Modified: 1 Nov 2005 20:23
Reporter: Ulf Küßner Email Updates:
Status: Closed Impact on me:
None 
Category:MySQL Server Severity:S2 (Serious)
Version:5.0.11 OS:Mac OS X (osx/winxp/..)
Assigned to: Alexey Botchkov CPU Architecture:Any

[26 Aug 2005 17:35] Ulf Küßner
Description:
The big/little endian support in the WKB functions is seemingly non existant.
Even the documentation is absurd:
-- quote --
A WKB which corresponds to POINT(1,1) looks like this sequence of 21 bytes:

0101000000000000000000F03F000000000000F03F
Where, consequently,

Byte order : 01  -- this implies little endian representation as defined in OGC Simple features /part 3.3
WKB type   : 01000000 -- this is a big endian representation
X          : 000000000000F03F -- this is little endian again
Y          : 000000000000F03F
---
Even worse - the ByteOrder byte is not at all regarded.

How to repeat:
select (asWKT(geomfromwkb((0x010100000000000000000024400000000000002440))));
will produce
POINT(10 10)

select (asWKT(geomfromwkb((0x000100000000000000000024400000000000002440))));
see the big endian bit in front, will produce
POINT(10 10) 

select (asWKT(geomfromwkb((0x000100000000000000000024404024000000000000))));
mind the big endian Y coordinate, will produce
POINT(10 4.5849291934068e-320)   
-- this is, actually, exactly the wrong way of interpreting the string. It acutually should produce
POINT(4.5849291934068e-320 10)

Suggested fix:
Make endian encoding consistent! Don't use big endian for the WKBtype and little endian for the PointCoordinates.
If you must, declare only little endian valid, but don't mix it.

Mind the ByteOrderByte, don't just ignore it.
[31 Aug 2005 15:50] Jorge del Conde
Tested w/5.0.12 from bk:

jorge-/home/jorge> mysql
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 2 to server version: 5.0.12-beta

Type 'help;' or '\h' for help. Type '\c' to clear the buffer.

mysql> select (asWKT(geomfromwkb((0x010100000000000000000024400000000000002440))));
+----------------------------------------------------------------------+
| (asWKT(geomfromwkb((0x010100000000000000000024400000000000002440)))) |
+----------------------------------------------------------------------+
| POINT(10 10)                                                         |
+----------------------------------------------------------------------+
1 row in set (0.00 sec)

mysql> select (asWKT(geomfromwkb((0x000100000000000000000024400000000000002440))));
+----------------------------------------------------------------------+
| (asWKT(geomfromwkb((0x000100000000000000000024400000000000002440)))) |
+----------------------------------------------------------------------+
| POINT(10 10)                                                         |
+----------------------------------------------------------------------+
1 row in set (0.00 sec)

mysql> select (asWKT(geomfromwkb((0x000100000000000000000024404024000000000000))));
+----------------------------------------------------------------------+
| (asWKT(geomfromwkb((0x000100000000000000000024404024000000000000)))) |
+----------------------------------------------------------------------+
| POINT(10 4.5849291934068e-320)                                       |
+----------------------------------------------------------------------+
1 row in set (0.00 sec)

mysql>
[21 Sep 2005 9:07] Bugs System
A patch for this bug has been committed. After review, it may
be pushed to the relevant source trees for release in the next
version. You can access the patch from:

  http://lists.mysql.com/internals/30138
[1 Nov 2005 20:23] Paul DuBois
Noted in 4.1.16 changelog.
[16 Mar 2006 12:00] Joakim Ahlen
This bug is still existing in 5.0.13. When will the patch be included in an official release?

mysql> select version();
+------------------+
| version()        |
+------------------+
| 5.0.13-rc-nt-log |
+------------------+
1 row in set (0.01 sec)

mysql> select (asWKT(geomfromwkb((0x010100000000000000000024400000000000002440))));
+----------------------------------------------------------------------+
| (asWKT(geomfromwkb((0x010100000000000000000024400000000000002440)))) |
+----------------------------------------------------------------------+
| POINT(10 10)                                                         |
+----------------------------------------------------------------------+
1 row in set (0.02 sec)

mysql> select (asWKT(geomfromwkb((0x000100000000000000000024400000000000002440))));
+----------------------------------------------------------------------+
| (asWKT(geomfromwkb((0x000100000000000000000024400000000000002440)))) |
+----------------------------------------------------------------------+
| POINT(10 10)                                                         |
+----------------------------------------------------------------------+
1 row in set (0.02 sec)
[16 Mar 2006 12:14] Joakim Ahlen
Sorry, this bug seems to have been fixed at least in 5.0.19, although that was not stated in any of the changelogs between 5.0.11 and 5.0.19.