php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #33693 mssql uniqueidentifier in select crashes php
Submitted: 2005-07-14 10:53 UTC Modified: 2013-02-18 00:15 UTC
Votes:10
Avg. Score:4.6 ± 0.7
Reproduced:10 of 10 (100.0%)
Same Version:2 (20.0%)
Same OS:4 (40.0%)
From: r dot vanicek at seznam dot cz Assigned:
Status: No Feedback Package: Sybase-ct (ctlib) related
PHP Version: 4.4.0 OS: Linux (Debian 3.1)
Private report: No CVE-ID: None
Have you experienced this issue?
Rate the importance of this bug to you:

 [2005-07-14 10:53 UTC] r dot vanicek at seznam dot cz
Description:
------------
I am connecting from PHP to Sybase and MSSQL. I have sybase-ct extension enabled. I use freetds-0.63. When I select from MSSQL any column of type "uniqueidentifier", PHP crashes on fetch.

The problem is conversion. Sybase-ct module does not handle CS_UNIQUE_TYPE,  and tries to store the 38 byte string that freetds returns to it into 16 byte string. Freetds refuses to do so and signals an error, which is probably fatal.

Test suite: see reproduce code.

The solution I suggest is to intoduce CS_UNIQUE_TYPE into php_sybase_ct.c, function php_sybase_fetch_result_set for example like this:

			case CS_DECIMAL_TYPE:
				result->datafmt[i].maxlength = result->datafmt[i].precision + 3;
				/* numeric(10) vs numeric(10, 1) */
				result->numerics[i] = (result->datafmt[i].scale == 0) ? 3 : 2;
				break;
			case CS_UNIQUE_TYPE:
				result->datafmt[i].maxlength = 38;
				result->numerics[i] = 0;
				break;
			default:
				result->datafmt[i].maxlength++;
				result->numerics[i] = 0;
				break;



This solution works for me quite well.


Reproduce code:
---------------
create table TEST (a int, b varchar, c uniqueidentifier);
insert into TEST values (1,'hello',newid());

sybase_connect( "srv", "uid", "pwd" );
sybase_select_db( "dbname" );

// this works fine
$res = sybase_query( "select a,b from TEST" );
$row = sybase_fetch_array( $res );

// this crashes
$res = sybase_query( "select a,b,c from TEST" );
$row = sybase_fetch_array( $res );

It is all the same if you use mssql_ functions instead of sybase_ functions.


Expected result:
----------------
eg. row containing
1
'hello'
'EB668095-F85D-4C59-A202-120C5CE1B65'

Actual result:
--------------
crash, in Apache error.log I see this:

[notice] child pid 18857 exit signal Segmentation fault (11)
error_handler: Data-conversion resulted in overflow.


Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2005-07-18 02:37 UTC] sniper@php.net
Not enough information was provided for us to be able
to handle this bug. Please re-read the instructions at
http://bugs.php.net/how-to-report.php

If you can provide more information, feel free to add it
to this bug and change the status back to "Open".

Thank you for your interest in PHP.



 [2005-07-26 01:00 UTC] php-bugs at lists dot php dot net
No feedback was provided for this bug for over a week, so it is
being suspended automatically. If you are able to provide the
information that was originally requested, please do so and change
the status of the bug back to "Open".
 [2007-07-12 21:41 UTC] shiftlessways at hotmail dot com
This bug still seems to exist in current php 5 and 6 snapshots.

I don't know how exactly there is not enough info in the original post but while the provided patch does fix the problem and work perfectly, patching php may not be an option. So altering your sql to cast the id value into a varchar before it is returned can be used as a workaround untill this ever gets fixed.
 [2007-09-27 10:50 UTC] walter at wjd dot nu
You need tds version 7.0 for the bug to rear it's head.

E.g. by "tds version = 7.0" in /etc/freetds/freetds.conf or with TDSVER=7.0 environment variable.
(The 7.0 version transmits UCS-2 instead of ASCII which is used with 4.2) 

I'd really like this fixed, because I need 7.0 for working UTF8 support (with NVARCHARs in my database).

When PHP is run from an apache module and the bug occurs, apache fails to serve (crashes?) any page that uses sybase-connections!


#--------------------------------------------------
# Versions
#--------------------------------------------------
PHP 5.2.0-8+etch7 (cli) (built: Jul  2 2007 21:46:15)
Copyright (c) 1997-2006 The PHP Group
Zend Engine v2.2.0, Copyright (c) 1998-2006 Zend Technologies

#--------------------------------------------------
# Output of my own test code using SELECT *
#--------------------------------------------------
$ TDSVER=4.2 php test2.php
Success!
$ TDSVER=7.0 php test2.php
error_handler: Data-conversion resulted in overflow.
Segmentation fault (core dumped)
 [2008-09-03 09:45 UTC] steveh at brendata dot co dot uk
This is still an issue on the php 5.2.1, is it intended to fix this?
 [2008-09-03 09:53 UTC] pajoye@php.net
Can you try using the latest 5.2.x and 5.3.0 snapshot?
 [2008-09-11 01:00 UTC] php-bugs at lists dot php dot net
No feedback was provided for this bug for over a week, so it is
being suspended automatically. If you are able to provide the
information that was originally requested, please do so and change
the status of the bug back to "Open".
 [2010-09-23 11:35 UTC] t dot nickl at exse dot de
This is not fixed in php 5.2.1. Did you fix it? Why is this closed?
 [2010-09-23 11:43 UTC] pajoye@php.net
-Status: No Feedback +Status: Feedback
 [2010-09-23 11:43 UTC] pajoye@php.net
It is not marked as fixed but as "no feedback".

Also 5.2.1 is dead, dead and dead. Please try using 5.3.3 or 5.2.14. Also if you use sqlserver you should use mssql extensions or odbc instead of sybase_ct.
 [2013-02-18 00:15 UTC] php-bugs at lists dot php dot net
No feedback was provided. The bug is being suspended because
we assume that you are no longer experiencing the problem.
If this is not the case and you are able to provide the
information that was requested earlier, please do so and
change the status of the bug back to "Open". Thank you.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Sun Jun 16 16:01:28 2024 UTC