Skip to content

Commit dc93f82

Browse files
committed
Fixed bit adjustment to only trim the 4 nul bytes on the left
1 parent 5622063 commit dc93f82

File tree

1 file changed

+7
-2
lines changed

1 file changed

+7
-2
lines changed

src/Types/Geometry.php

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,9 +51,14 @@ public static function getWKTClass($value)
5151

5252
public static function fromWKB($wkb)
5353
{
54+
// mysql adds 4 NUL bytes at the start of the binary
55+
$prefix = "\0\0\0\0";
56+
if (substr($wkb, 0, strlen($prefix)) == $prefix) {
57+
$wkb = substr($wkb, strlen($prefix));
58+
}
59+
5460
$parser = new Parser(new Factory());
55-
// return $parser->parse(ltrim($wkb)); // using ltrim to remove the 4 nul bytes at the start of the string
56-
return $parser->parse(substr($wkb, 4)); // mysql adds 4 NUL bytes at the start of the binary
61+
return $parser->parse($wkb);
5762
}
5863

5964
public static function fromWKT($wkt)

0 commit comments

Comments
 (0)