Bug #74247 [Opn]: Mysql Blob field data gets corrupted after 16MB
| From: | support at dsolutions dot lv | Date: | Tue, 14 Mar 2017 22:06:15 +0000 |
| Subject: | Bug #74247 [Opn]: Mysql Blob field data gets corrupted after 16MB | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-207836@lists.php.net to get a copy of this message | ||
Edit report at https://bugs.php.net/bug.php?id=74247&edit=1
ID: 74247
User updated by: support at dsolutions dot lv
Reported by: support at dsolutions dot lv
-Summary: Blob
+Summary: Mysql Blob field data gets corrupted after 16MB
Status: Open
Type: Bug
Package: MySQLi related
Operating System: Linux
PHP Version: 7.1.3RC1
Block user comment: N
Private report: N
New Comment:
Correction: Since PHP version *7.0.15*
Previous Comments:
------------------------------------------------------------------------
[2017-03-14 21:57:20] support at dsolutions dot lv
Description:
------------
Since PHP version 7.1.15 when reading a longblob field from MySQL, mysqlnd driver inserts a 0x00
byte at position 16777204 ( or 2^24-12). Therefore all data following said zero is shifted 1 byte to
the right.
However the total length of the data is unchanged, as the last byte of the blob is not returned.
Test script is for mysqli, however I was able to reproduce the same behaviour with pdo.
I have some suspicion that the problem resides within the file
"ext/mysqlnd/mysqlnd_wireprotocol.c" as it was modified for version 7.0.15.
Test script:
---------------
echo "\nPHP version:".phpversion();
$mysqli = new mysqli('localhost', 'root', '', 'test');
$mysqli->query("DROP TABLE IF EXISTS
blob_tb;");
$mysqli->query("CREATE TABLE blob_tb (bdata longblob);");
$sql = "INSERT INTO blob_tb (bdata) VALUES(?)";
$insertStm = $mysqli->prepare($sql);
$blob = NULL;
$insertStm->bind_param('b', $blob);
$crypto_strong=false;
$blob = (binary) openssl_random_pseudo_bytes (20*1024*1024,$crypto_strong);
$insertStm->send_long_data(0, $blob);
$insertStm->execute();
$insertStm->close();
echo "\nInserted data md5: ".md5($blob).", len ".strlen($blob);
$selectStm = $mysqli->prepare("SELECT bdata FROM blob_tb LIMIT 1");
$selectStm->execute();
$selectStm->bind_result($savedBlob);
$selectStm->fetch();
$selectStm->close();
echo "\nAre the blobs equal?: " . ((int) ($blob == $savedBlob));
echo "\nSelected data: md5: ".md5($savedBlob);
echo "\nSQL md5(): ".$mysqli->query("select md5(bdata) as database_md5 from
blob_tb;")->fetch_assoc()['database_md5'];
$mysqli->close();
Expected result:
----------------
PHP version:7.0.14
Inserted data md5: 7792a7fd3351033132f991e7a8e939f3, len 20971520
Are the blobs equal?: 1
Selected data: md5: 7792a7fd3351033132f991e7a8e939f3
SQL md5(): 7792a7fd3351033132f991e7a8e939f3
PHP version:7.0.13-1+deb.sury.org~trusty+1
Inserted data md5: b6130b103663d6facbcba10301dd23e1, len 20971520
Are the blobs equal?: 1
Selected data: md5: b6130b103663d6facbcba10301dd23e1
SQL md5(): b6130b103663d6facbcba10301dd23e1
Actual result:
--------------
On Centos 7:
PHP version:7.0.16
Inserted data md5: 7354bdcb5ee180e069fb686bd289242c, len 20971520
Are the blobs equal?: 0
Selected data: md5: 887f9bbf56e7ad378e8672277d07c267
SQL md5(): 7354bdcb5ee180e069fb686bd289242c
PHP version:7.0.15
Inserted data md5: e13724a895dc46e073c4c7ddb005d09d, len 20971520
Are the blobs equal?: 0
Selected data: md5: aa68f482f6a75ae77027728a09485da0
SQL md5(): e13724a895dc46e073c4c7ddb005d09d
On Ubuntu:
PHP version:7.0.16-4+deb.sury.org~trusty+1
Inserted data md5: 5ab7bb3d517fbfbbd21ec02c48da2d88, len 20971520
Are the blobs equal?: 0
Selected data: md5: 9eb90f968797d617b7385fd166f34067
SQL md5(): 5ab7bb3d517fbfbbd21ec02c48da2d88
------------------------------------------------------------------------
--
Edit this bug report at https://bugs.php.net/bug.php?id=74247&edit=1