php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #71291 Blob files are corrupted when insert on a 64bit OS.
Submitted: 2016-01-05 18:30 UTC Modified: 2017-09-30 17:51 UTC
From: josemalonsom at yahoo dot es Assigned:
Status: Closed Package: PDO_INFORMIX (PECL)
PHP Version: Irrelevant OS: Ubuntu 15.10 x86_64
Private report: No CVE-ID: None
 [2016-01-05 18:30 UTC] josemalonsom at yahoo dot es
Description:
------------
When a binary file is inserted in a blob field the content is saved partially corrupting the file. Tested in a 32bit OS and it works fine but the file is not saved correctly when the platform is 64bit.

PHP: tested in versions 5.4.45, 5.5.30 and 5.6.16.
CSDK: 4.10.FC6DE

Test script:
---------------
// $con is a valid PDO_INFORMIX connection

$base64BlobFile = 'UEsDBBQAAAAIABiIJEj+Q0o8DwAAABIAAAAJABwAZmlsZTEudHh0VVQJAA'
    . 'Mvl4pWaJeKVnV4CwABBOgDAAAE6AMAAMvJzEs15MoBkkZg0pgLAFBLAQIeAxQAAAAIABiI'
    . 'JEj+Q0o8DwAAABIAAAAJABgAAAAAAAEAAAC0gQAAAABmaWxlMS50eHRVVAUAAy+XilZ1eA'
    . 'sAAQToAwAABOgDAABQSwUGAAAAAAEAAQBPAAAAUgAAAAAA';

$blobFile = '/tmp/file1.zip';

file_put_contents($blobFile, base64_decode($base64BlobFile));

try {
    $con->exec('DROP TABLE blob_test');
}
catch (Exception $e) {}

$con->exec('CREATE TABLE blob_test (blob_column BLOB)');

$fh = fopen($blobFile, 'rb');

$stmt = $con->prepare('INSERT INTO blob_test (blob_column) VALUES (?)');
$stmt->bindParam(1, $fh, PDO::PARAM_LOB);
$stmt->execute();

$stmt = $con->prepare('SELECT FIRST 1 blob_column FROM blob_test');
$stmt->bindColumn(1, $blob, PDO::PARAM_LOB);
$stmt->execute();
$stmt->fetch(PDO::FETCH_BOUND);

fseek($fh, 0);
$expectedContent = stream_get_contents($fh);
$actualContent = stream_get_contents($blob);

print $expectedContent == $actualContent ? "Test ok\n" : "Test fail\n";

Expected result:
----------------
The file should be inserted correctly.

Actual result:
--------------
The inserted file is corrupted.

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2017-03-28 08:33 UTC] javier dot sagrera at uk dot ibm dot com
This is not a PDO_INFORMIX bug. It was caused by a defect within the ODBC driver (idsdb00512869).
The upcoming CSDK 4.10.xC9 version solves this problem.
 [2017-09-30 17:51 UTC] josemalonsom at yahoo dot es
-Status: Open +Status: Closed
 [2017-09-30 17:51 UTC] josemalonsom at yahoo dot es
I was waiting to test it with the CSDK 4.10.xC9 you mentioned before closing the bug. I have just doing it and I can confirm that solves the problem.

Thank you very much.
 
PHP Copyright © 2001-2019 The PHP Group
All rights reserved.
Last updated: Wed Oct 23 21:01:33 2019 UTC