Bug #65947 [Asn]: basename is no more working after fgetcsv in certain situation
| From: | laruence@php.net | Date: | Wed, 06 Nov 2013 08:40:41 +0000 |
| Subject: | Bug #65947 [Asn]: basename is no more working after fgetcsv in certain situation | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-182614@lists.php.net to get a copy of this message | ||
Edit report at https://bugs.php.net/bug.php?id=65947&edit=1
ID: 65947
Updated by: laruence@php.net
Reported by: phpbugs at dev dot bitadept dot org
Summary: basename is no more working after fgetcsv in certain
situation
Status: Assigned
Type: Bug
Package: Filesystem function related
Operating System: Gentoo Linux
PHP Version: 5.5.5
Assigned To: rasmus
Block user comment: N
Private report: N
New Comment:
I was keep looking this, and found a suspicious codes:
define php_mblen(ptr, len) ((ptr) == NULL ? mbsinit(&BG(mblen_state)): (int)mbrlen(ptr, len,
&BG(mblen_state)))
it use mbsinit there, seems try to initialize the mblen_state, but:
"This function does not change the state identified by ps. Typical ways to make the state
pointed by ps an initial state are:
memset (ps,0,sizeof(*ps)); // ps points to zero-valued object
"
http://www.cplusplus.com/reference/cwchar/mbsinit/?kw=mbsinit
so I propose another fix... will attach later
rasmus, do you think it's right fix? thanks
Previous Comments:
------------------------------------------------------------------------
[2013-11-05 15:24:05] phpbugs at dev dot bitadept dot org
Applied patch to php-5.5.5-pl0-gentoo and works fine now.
------------------------------------------------------------------------
[2013-11-05 14:31:40] remi dot sauvat+php at gmail dot com
The patch is working for me. It fixes the basename and pathinfo php functions. Patch applied to PHP
5.5.4-pl0-gentoo
------------------------------------------------------------------------
[2013-11-05 13:41:59] laruence@php.net
a patch is attached to explain where the problems come from.
anyway maybe a better fix is clean the stat in getcsv.
------------------------------------------------------------------------
[2013-11-05 13:40:38] laruence@php.net
The following patch has been added/updated:
Patch Name: bug65947.patch
Revision: 1383658838
URL: https://bugs.php.net/patch-display.php?bug=65947&patch=bug65947.patch&revision=1383658838
------------------------------------------------------------------------
[2013-11-05 10:31:29] remi dot sauvat+php at inetprocess dot com
I have the same issue on Gentoo OS.
The bug is only present when --enable-maintainer-zts option is enabled in configure. (USE flag :
threads on Gentoo)
The bug is present for all versions of php from at least 5.2 to 5.5 when local is set to UTF-8 and
reading ISO-8859 csv data.
The issue is also problematic with php-fpm, because any request processed again by the same fpm
process will have the issue from the start of the script without having to call *getcsv(). The only
way to make it work again is to kill the fpm process.
Here is another code example with str_getcsv.
Test code :
--------------
<?php
$filename = 'test.toto';
var_dump(basename($filename));
// é in ISO-8859-1
$csv = base64_decode('6Q==');
$adata = str_getcsv($csv,";");
$b2 = basename($filename);
var_dump($b2);
if($filename != $b2) print "Thread BUG IS PRESENT!!!!\n";
Expected results with php-fpm:
-------------
# 1st request :
string(8) "test.txt"
string(8) "test.txt"
# 2nd request :
string(8) "test.txt"
string(8) "test.txt"
Actual results :
-----------------
# 1st request :
string(8) "test.txt"
string(0) ""
Thread BUG IS PRESENT!!!!
# 2nd request :
string(0) ""
string(0) ""
Thread BUG IS PRESENT!!!!
------------------------------------------------------------------------
The remainder of the comments for this report are too long. To view
the rest of the comments, please view the bug report online at
https://bugs.php.net/bug.php?id=65947
--
Edit this bug report at https://bugs.php.net/bug.php?id=65947&edit=1