Bug #65947 [Com]: basename is no more working after fgetcsv in certain situation

From: Date: Tue, 05 Nov 2013 14:31:41 +0000
Subject: Bug #65947 [Com]: basename is no more working after fgetcsv in certain situation
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-182608@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 Comment by: remi dot sauvat+php at gmail dot com Reported by: phpbugs at dev dot bitadept dot org Summary: basename is no more working after fgetcsv in certain situation Status: Open Type: Bug Package: Filesystem function related Operating System: Gentoo Linux PHP Version: 5.5.5 Block user comment: N Private report: N New Comment: The patch is working for me. It fixes the basename and pathinfo php functions. Patch applied to PHP 5.5.4-pl0-gentoo Previous Comments: ------------------------------------------------------------------------ [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!!!! ------------------------------------------------------------------------ [2013-10-22 14:10:52] phpbugs at dev dot bitadept dot org Description: ------------ Calls to basename and pathinfo are no more working after using fgetcsv. This is the case when the system's locale is set to utf8 an you try to parse a file using fgetcsv that is encoding in iso8859-1 and contains some german Umlaute. Setting the locale to iso8859-1 in the first place is fixing the problem, but this should not happen at all. System information: $ uname -a Linux Merlin 3.5.4-hardened-r1 #2 SMP Mon Jan 21 09:21:26 CET 2013 x86_64 Intel(R) Core(TM) i5 CPU M 520 @ 2.40GHz GenuineIntel GNU/Linux $ locale LANG= LC_CTYPE="de_DE.UTF-8" LC_NUMERIC="de_DE.UTF-8" LC_TIME="de_DE.UTF-8" LC_COLLATE="de_DE.UTF-8" LC_MONETARY="de_DE.UTF-8" LC_MESSAGES="de_DE.UTF-8" LC_PAPER="de_DE.UTF-8" LC_NAME="de_DE.UTF-8" LC_ADDRESS="de_DE.UTF-8" LC_TELEPHONE="de_DE.UTF-8" LC_MEASUREMENT="de_DE.UTF-8" LC_IDENTIFICATION="de_DE.UTF-8" LC_ALL=de_DE.UTF-8 $ php -v PHP 5.5.5-pl0-gentoo (cli) (built: Oct 22 2013 15:56:09) Copyright (c) 1997-2013 The PHP Group Zend Engine v2.5.0, Copyright (c) 1998-2013 Zend Technologies Test script: --------------- <?php $a = '/tmp/somefile.csv'; echo "define: ".basename($a)."\n"; $fp = fopen($a, 'r'); echo "fopen: ".basename($a)."\n"; while (($lineArray = fgetcsv($fp, 0, ';')) !== FALSE); echo "fgetcsv: ".basename($a)."\n"; fclose($fp); echo "fclose: ".basename($a)."\n"; Expected result: ---------------- define: somefile.csv fopen: somefile.csv fgetcsv: somefile.csv fclose: somefile.csv Actual result: -------------- define: somefile.csv fopen: somefile.csv fgetcsv: fclose: ------------------------------------------------------------------------ -- Edit this bug report at https://bugs.php.net/bug.php?id=65947&edit=1

« previous php.bugs (#182608) next »