Edit report at https://bugs.php.net/bug.php?id=46473&edit=1

 ID:                 46473
 Comment by:         brandonkirsch at gmail dot com
 Reported by:        philippe dot marasse at ac-poitiers dot fr
 Summary:            php segfaults on some queries using pdo_odbc &
                     ibm-db2 on a 64bits platform
 Status:             Assigned
 Type:               Bug
 Package:            PDO related
 Operating System:   Linux Red Hat EL5 x86_64
 PHP Version:        5.2.6
 Assigned To:        iodbc
 Block user comment: N
 Private report:     N

 New Comment:

I am very familiar with this problem - IT IS NOT A BUG IN PHP.

64-bit IBM iSeriesAccess ODBC drivers are built against an antiquated 
definition of what 64-bit ODBC should be. Instead, the IBM drivers use 32-bit 
values in places where 64-bits should be used.

The end result is that a 32-bit value ("-1" to represent NULL) is interpreted 
by 64-bit PHP as a large number, causing it to read an invalid memory address 
and therefore segfault.

You can ask IBM for a better ODBC driver, but they ignored us when we tried.

I have a custom patch for php_odbc.c that "fixes" the problem by hacking up PHP 
ODBC bindings to treat all ODBC SQL_NULL_DATA values as 32-bit. There are small 
potential downsides that can occur if you use this patch with a real 64-bit 
ODBC driver AND you try to access fields > 4GB.

http://www.perceptionilluminates.com/php/php_odbc.c -- It's antiquated (PHP 
5.2.17) but it is also well commented, so you can port the hack to a modern 
version if you'd like.


Previous Comments:
------------------------------------------------------------------------
[2009-06-30 19:23:57] d dot stcyr at streamfoundry dot com

Was able to circumvent by configuring (now, PHP 5.2.10) with --enable-debug.  
PHP 5.2.10 without --enable-debug fails the same way as did 5.2.9.  Can someone 
advise if this is the same problem and a prognosis for correction?

------------------------------------------------------------------------
[2009-06-24 15:57:26] d dot stcyr at streamfoundry dot com

I believe we have a same/similar situation running PHP 5.2.9 on 64-bit SLES10 - 
with the ibm-db2 1.8.2 pdo_odbc extension. Getting a "Child pid nnn exit signal 
Segmentation fault (11)". Here is a simple recreate script trying to connect to 
the DB2 "SAMPLE" database:

<?php
 $dbconn = new PDO('odbc:SAMPLE','db2inst1','pw'); /* pw not actual pw */
?>

Program terminated with signal 11, Segmentation fault.
#0  _zval_ptr_dtor (zval_ptr=0x3fffff31c70)
    at /opt/SFI/php-5.2.9/Zend/zend_execute_API.c:412
412             (*zval_ptr)->refcount--;

Backtrace:
#0  _zval_ptr_dtor (zval_ptr=0x3fffff31c70)
    at /opt/SFI/php-5.2.9/Zend/zend_execute_API.c:412
#1  0x0000020000a36282 in zend_do_fcall_common_helper_SPEC (
    execute_data=0x3fffff31ec0) at /opt/SFI/php-5.2.9/Zend/zend_execute.h:155
#2  0x0000020000a26992 in execute (op_array=0x20002bb0d90)
    at /opt/SFI/php-5.2.9/Zend/zend_vm_execute.h:92
#3  0x0000020000a032ac in zend_execute_scripts (type=<value optimized out>,
    retval=0x0, file_count=2) at /opt/SFI/php-5.2.9/Zend/zend.c:1134
#4  0x00000200009ba4c4 in php_execute_script (primary_file=0x3fffff344d0)
    at /opt/SFI/php-5.2.9/main/main.c:2023
#5  0x0000020000a970c8 in php_handler (r=0x2aaaade5ba8)
    at /opt/SFI/php-5.2.9/sapi/apache2handler/sapi_apache2.c:632
#6  0x000002aaaaaedce0 in ap_run_handler () from /usr/sbin/httpd2-prefork
#7  0x000002aaaaaf1516 in ap_invoke_handler () from /usr/sbin/httpd2-prefork
#8  0x000002aaaaafccd8 in ap_process_request () from /usr/sbin/httpd2-prefork
#9  0x000002aaaaafa08c in ?? () from /usr/sbin/httpd2-prefork
#10 0x000002aaaaaf55b4 in ap_run_process_connection ()
   from /usr/sbin/httpd2-prefork
#11 0x000002aaaab01190 in ?? () from /usr/sbin/httpd2-prefork
#12 0x000002aaaab014b0 in ?? () from /usr/sbin/httpd2-prefork
#13 0x000002aaaab0158a in ?? () from /usr/sbin/httpd2-prefork
#14 0x000002aaaab021d4 in ap_mpm_run () from /usr/sbin/httpd2-prefork
#15 0x000002aaaaad8646 in main () from /usr/sbin/httpd2-prefork

Please let me know if this falls within the known exposure of the work being 
done on this bug. And a status?

Thanks.

------------------------------------------------------------------------
[2009-04-25 15:15:16] j...@php.net

iodbc: What is the status with this fix? (if this still isn't fixed, 
please update the PHP version..)

------------------------------------------------------------------------
[2008-11-07 11:45:59] io...@php.net

I am working on a fix for pdo_odbc to bring it up to ODBC 3.51 API 
specification including full 64bit support, similar to the work i did on 
the regular ext/odbc code.

------------------------------------------------------------------------
[2008-11-03 15:35:13] philippe dot marasse at ac-poitiers dot fr

Description:
------------
On our both platforms (32 & 64 bits), we have php compiled with support for IBM 
DB2 database via pdo_odbc extension. We ran into unexpected segfaults deploying 
a new application on a 64 bits server.

We have tested several client version of DB2 but nothing helped.

At last, it seemed that pdo_odbc extensions did not compile properly, as we got 
several warnings like :

passing argument 2 of 'SQLRowCount' from incompatible pointer type

Bug #32830 (related to odbc, not pdo_odbc) points out the same issue.

We wrote a little patch that works for us (tm), available at :

http://huan.ac-poitiers.fr/pdo_odbc_db2-x86_64.patch

Rgds.

Reproduce code:
---------------
<?php
  $toto = new PDO("odbc:mydb","user","password");
  $req = "SELECT ETA_DENOMINATION FROM ETABLISSEMENT WHERE ETA_DEPARTEMENT = 16 
AND ETA_RNE = '0160001P'";
  $machin = $toto->query($req);
  $truc = $machin->fetchObject();
?>


Expected result:
----------------
nothing indeed :-), it's just a script we used to isolate a query which crashes 
only on our 64bits servers (of course, it works fine on 32bits platform).

Actual result:
--------------
segfault... unless the value of ETA_DENOMINATION is not NULL.


------------------------------------------------------------------------



-- 
Edit this bug report at https://bugs.php.net/bug.php?id=46473&edit=1

Reply via email to