php / php/php-src

Fetching BLOB via PDO odbc is missing parts of the result

Open
#8,622 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Bug Extension: pdo_odbc Status: Needs Triage
Dominant language
C
Stars
40.4k
Forks
8.1k
Avg merge
2d 13h
Merged PRs (30d)
96

Description

Description

We're trying to stream an image from our IBM i filesystem (IFS) by fetching a blob via PDO. However the result is missing half the blob in a repeating pattern.

The following code:

$db = new PDO("odbc:DSN=NAME", 'user', 'pass');
$stmt = $db->prepare("SELECT * FROM TABLE(QSYS2.IFS_READ_BINARY('/path/to/file.jpg'))");
$stmt->execute();
$stmt->bindColumn(1, $type, PDO::PARAM_STR, 256);
$stmt->bindColumn(2, $lob, PDO::PARAM_LOB);
$stmt->fetch(PDO::FETCH_BOUND);

Resulted in this output:

FFD8FFE000104A46494600010101007800780000FFE1002C4578696600004D4D002A000000080001013100020000000A0000001A00000000477265656E73686F7400FFDB00430007050506050407060506080707080A110B0A09090A150F100C1118151A19181518171B1E27211B1D251D1718222E222528292B2C2B1A202F30BFFC400B5100002010303020403050504040000017D01020300041105122131410613516107227114328191A1082342B1C11552D1F02433627282090A161718191A25262728292A3435363738393A434445464748494A535455565758595A636465666768696A737475767778797A838485868788898A9293949596979899922328108144291A1B1C109233352F0156272D10A162434E125F11718191A262728292A35363738393A434445464748494A535455565758595A636465666768696A737475767778797A82838485868788898A92939495969798999AA2A3A4A5A6A7A8A9AAB2B3B4B5B6B7B8B9BAC2C3C4C5C6C7C8C9CAD2D3D4D5D6D7D8D9DAEA0028A28A0028A28A0028A28A0028A28A0028A28A002B85F8A73EB3A37846FF5FD0FC437DA7CB691C616DA286D9E262640A58F99133670DD980E071D73DD573BE3EF0FDDF8ABC0DA8E8DA7C90C7717410234EC420C48AC724027A03DA90D6E62F8D2EF55F087C3DB8BB4F13DE4939BBB653A85E456A1ADE379A347C0589531B49D47C3F716B0C06D5B037A2C5B166508582866770707A9390BE245D7ECFC7FE1ED32CFC61AB4369ACCB7465416F647C911C7BD56326DC9C678F9B71C77CF356B53F0D6BFE2AD7743BAD6EC345D3028A28A0028A28A0028A28A0028A28A0028A28A0028A28A0028A28A0028A28A0028A28A0028A28A0028A28A0028A28A0028A28A0028A28A0028A28A0028A28A0028A28A0028A28A0028A28A0028A28A0028A28A0028A28A0028A28A0028A28A00FFFD9

But I expected this output instead:

FFD8FFE000104A46494600010101007800780000FFE1002C4578696600004D4D002A000000080001013100020000000A0000001A00000000477265656E73686F7400FFDB00430007050506050407060506080707080A110B0A09090A150F100C1118151A19181518171B1E27211B1D251D1718222E222528292B2C2B1A202F332F2A32272A2B2AFFDB0043010708080A090A140B0B142A1C181C2A2A2A2A2A2A2A2A2A2A2A2A2A2A2A2A2A2A2A2A2A2A2A2A2A2A2A2A2A2A2A2A2A2A2A2A2A2A2A2A2A2A2A2A2A2A2A2A2A2AFFC0001108005C00C803012200021101031101FFC4001F0000010501010101010100000000000000000102030405060708090A0BFFC400B5100002010303020403050504040000017D01020300041105122131410613516107227114328191A1082342B1C11552D1F02433627282090A161718191A25262728292A3435363738393A434445464748494A535455565758595A636465666768696A737475767778797A838485868788898A92939495969798999AA2A3A4A5A6A7A8A9AAB2B3B4B5B6B7B8B9BAC2C3C4C5C6C7C8C9CAD2D3D4D5D6D7D8D9DAE1E2E3E4E5E6E7E8E9EAF1F2F3F4F5F6F7F8F9FAFFC4001F0100030101010101010101010000000000000102030405060708090A0BFFC400B51100020102040403040705040400010277000102031104052131061241510761711322328108144291A1B1C109233352F0156272D10A162434E125F11718191A262728292A35363738393A434445464748494A535455565758595A636465666768696A737475767778797A82838485868788898A92939495969798999AA2A3A4A5A6A7A8A9AAB2B3B4B5B6B7B8B9BAC2C3C4C5C6C7C8C9CAD2D3D4D5D6D7D8D9DAE2E3E4E5E6E7E8E9EAF2F3F4F5F6F7F8F9FAFFDA000C03010002110311003F00FA468A28A0028A28A0028A28A0028A28A0028A28A0028A28A0028A28A0028A28A0028A28A0028A28A0028A28A0028A28A0028A28A0028A28A0028A28A0028A28A0028A28A0028A28A0028A28A0028A28A0028A28A0028A28A0028A28A0028A28A0028A28A0028A28A0028A28A0028A28A0028A28A002B85F8A73EB3A37846FF5FD0FC437DA7CB691C616DA286D9E262640A58F99133670DD980E071D73DD573BE3EF0FDDF8ABC0DA8E8DA7C90C7717410234EC420C48AC724027A03DA90D6E62F8D2EF55F087C3DB8BB4F13DE4939BBB653A85E456A1ADE379A347C0589531B4B1CB29C66AEE87AADB4B63A9CFA078CCF8CAE60B72E96BF68B37D8F825466DE34237118F9B3D38AB7E3AD06FFC43E136D3F4A36FF6B5B9B69D05CC8C91B7953248416556232148CE0D5CB09FC497115CAEA9A7E95A7C9E5FFA3BDBDF49760BF3F7D5A18B81C743CFB51BA7FD74425A58E4BE1F788DBC44D04973E33927D65549D47C3F716B0C06D5B037A2C5B166508582866770707A9390BE245D7ECFC7FE1ED32CFC61AB4369ACCB7465416F647C911C7BD56326DC9C678F9B71C77CF356B53F0D6BFE2AD7743BAD6EC345D31348BC5BB5BAB4BB92EAE1F1FF002C94B431EC56FE2396CE00C771AFAE787AEF53F1B786758824856DF496B933ABB10EDE645B176803079EB922AB7B316D746F5AC2F6F6914335CCB74E8A15A79828790FF78850AB93EC00F6A968A290C28A28A0028A28A0028A28A0028A28A0028A28A0028A28A0028A28A0028A28A0028A28A0028A28A0028A28A0028A28A0028A28A0028A28A0028A28A0028A28A0028A28A0028A28A0028A28A0028A28A0028A28A0028A28A0028A28A0028A28A0028A28A0028A28A0028A28A0028A28A0028A28A0028A28A0028A28A0028A28A0028A28A0028A28A0028A28A0028A28A0028A28A0028A28A0028A28A0028A28A0028A28A0028A28A0028A28A0028A28A0028A28A00FFFD9

Comparing the two results below, we see the missing parts highlighted in blue:
image

We do get the right result using the same driver and query in different languages/ applications so it seems to be a problem in php odbc or PDO.
It also doesn't matter what file we try to stream.

PHP Version

PHP 8.1.5

Operating System

No response

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by reproducing the shown PDO ODBC query with PDO::bindColumn(PDO::PARAM_LOB) and PDO::fetch(PDO::FETCH_BOUND) on PHP 8.1.5, then inspect the PDO ODBC BLOB-fetch path. Done means the complete BLOB is returned without the repeating missing sections seen in the report.

Written by the indexing model from the issue text.

Assessment

Tech stack
php, sql
Domain
backend, databases
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
42/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.