|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
[2017-03-14 22:06 UTC] support at dsolutions dot lv
-Summary: Blob
+Summary: Mysql Blob field data gets corrupted after 16MB
[2017-03-14 22:06 UTC] support at dsolutions dot lv
[2017-03-14 22:06 UTC] spam2 at rhsoft dot net
[2017-03-14 22:16 UTC] support at dsolutions dot lv
-PHP Version: 7.1.3RC1
+PHP Version: 7.1.2
[2017-03-14 22:16 UTC] support at dsolutions dot lv
[2017-03-14 22:53 UTC] nikic@php.net
-Status: Open
+Status: Duplicate
[2017-03-14 22:53 UTC] nikic@php.net
|
|||||||||||||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Mon Oct 27 11:00:01 2025 UTC |
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