From:             russell dot brown at insignia dot com
Operating system: Windows 2000
PHP version:      4.3.4
PHP Bug Type:     Apache2 related
Bug description:  odbc_execute opens files in text mode using apache2

Description:
------------
If you use the quoted filename feature of odbc_execute() to load a binary
file into a blob field using the ODBC driver, it appears to use text mode
to open the file, and hence it truncates the data at the first 0x1A
sequence. 



If I use the command-line this appears to work perfectly, but via the SAPI
Apache2 dll it performs the truncation. It does not seem to be due to it
running as a different user, I've tried the tests logged in as the user on
the command-line and the results are the same.



It also doesn't seem to be possible to work around, because of another
problem where if you open the file yourself in binary mode and try to send
the data as a parameter to odbc_execute(), it will only upload ~4000
bytes. However, it does this on the command-line as well, so it is more
generally broken (I'll raise a separate bug request if you want about this
- I have some SQL logs which might be helpful).



The code example provided will perform both methods of upload (set
$method=1 for quoted filename, $method!=1 for uploading from memory
buffer), to make it easy to compare and contrast the differences. You
*must* upload a binary file more than 4096 bytes in size, and it must
contain at least 1 EOF somewhere in the first 4000 bytes to reproduce the
problem exactly. I'm talking to an Oracle 8.1.7 rdbms on a Solaris box.
I'm using an Oracle 8.1.7 client and corresponding ODBC driver version.



Please also note that I have not been able to test this against any other
database, ODBC driver, or against the apache 1.x SAPI dll. My reason for
using ODBC rather than the Oracle8 libraries (and the generic Oracle lib
doesn't handle blob fields) is because I'm about to move to using Oracle9
for which there are no php libraries available yet.

Reproduce code:
---------------
$binfile = "d:/blobs/testfile2.bin";

$blobid = 1000;

$method = 1;

if ($method == 1) {

        $parms = array("'".$binfile."'");

        $size_before = filesize($binfile);

} else {

        $buffer = "";

        $fh = fopen($binfile, "rb");

        while (!feof($fh)) { $buffer .= fgets($fh, 10240);}

        $parms = array($buffer);

        $size_before = strlen($buffer);

}

$conn = odbc_connect("xxxx", "xxxx", "xxxx");

//$res = odbc_prepare($conn, "INSERT INTO SSP_BLOB (BLOB_ID, BITS) VALUES
('$blobid', ?)");

$res = odbc_prepare($conn, "UPDATE SSP_BLOB SET BITS=? WHERE
BLOB_ID='$blobid'");

if (!odbc_execute($res, $parms)) { print "Execute failed:
".odbc_errormsg()."\n";}

$res = odbc_exec($conn, "SELECT DBMS_LOB.GETLENGTH(bits) FROM SSP_BLOB
WHERE BLOB_ID='$blobid'");

if (odbc_fetch_row($res)) {

        $size_after = odbc_result($res, 1);

        print "Size before: $size_before\nSize after: $size_after\n";

}

Expected result:
----------------
In an example uploading a 44,194 byte file, with the first EOF at the
182nd byte, in all cases one would expect output of:



Size before: 44194

Size after: 44194

Actual result:
--------------
Using same upload file as described in expected result:



Method 1 via CLI:

Size before: 44194

Size after: 44194



Method 1 via SAPI:

Size before: 44194 Size after: 182



Method !1 via CLI:

Size before: 44194

Size after: 4000



Method !1 via SAPI:

Size before: 44194 Size after: 4000

-- 
Edit bug report at http://bugs.php.net/?id=27281&edit=1
-- 
Try a CVS snapshot (php4):  http://bugs.php.net/fix.php?id=27281&r=trysnapshot4
Try a CVS snapshot (php5):  http://bugs.php.net/fix.php?id=27281&r=trysnapshot5
Fixed in CVS:               http://bugs.php.net/fix.php?id=27281&r=fixedcvs
Fixed in release:           http://bugs.php.net/fix.php?id=27281&r=alreadyfixed
Need backtrace:             http://bugs.php.net/fix.php?id=27281&r=needtrace
Need Reproduce Script:      http://bugs.php.net/fix.php?id=27281&r=needscript
Try newer version:          http://bugs.php.net/fix.php?id=27281&r=oldversion
Not developer issue:        http://bugs.php.net/fix.php?id=27281&r=support
Expected behavior:          http://bugs.php.net/fix.php?id=27281&r=notwrong
Not enough info:            http://bugs.php.net/fix.php?id=27281&r=notenoughinfo
Submitted twice:            http://bugs.php.net/fix.php?id=27281&r=submittedtwice
register_globals:           http://bugs.php.net/fix.php?id=27281&r=globals
PHP 3 support discontinued: http://bugs.php.net/fix.php?id=27281&r=php3
Daylight Savings:           http://bugs.php.net/fix.php?id=27281&r=dst
IIS Stability:              http://bugs.php.net/fix.php?id=27281&r=isapi
Install GNU Sed:            http://bugs.php.net/fix.php?id=27281&r=gnused
Floating point limitations: http://bugs.php.net/fix.php?id=27281&r=float

Reply via email to