From:             
Operating system: Windows Server 2008 R2 Foundatio
PHP version:      5.4SVN-2012-03-07 (SVN)
Package:          Filesystem function related
Bug Type:         Bug
Bug description:stat() fails with specific DBCS characters

Description:
------------
[not a #61309 report. this is another bug fix.]
[this is FYI patch. if you want to fix the problem on latest php5.4.]

stat() fails on all of following conditions:
- using DBCS enabled Windows env.
- a DBCS character contains backslash (\x5C) at second byte.

for example: /tmp/ソフト

(ソフト means "soft" in katakana, reading so-fu-to)

character -> to CP932(Shift_JIS) byte array -> to ascii

ソ -> 83 5C -> .\
フ -> 83 74 -> .t
ト -> 83 67 -> .g

I'll attach a patch for fixing this problem.

About my fix method:
- define IS_SLASH_PI(pointer, index). replace IS_SLASH(path[i-1]) with
IS_SLASH_PI(path, i-1).
- use IS_SLASH_PI instead of IS_SLASH_P and IS_SLASH.
- IS_SLASH can catch backslash in second byte of DBCS character. it is
problem.
- IS_SLASH_P of Win32 impl is dangerous because it decreases the pointer.
check this: #define IS_SLASH_PI(c,i) ... IsDBCSLeadByte((c)[i-1])

IS_SLASH_PI defines as follows:

#define IS_SLASH_PI(c,i)        ((c)[i] == '/' || \
        ((c)[i] == '\\' && ((i) == 0 || !IsDBCSLeadByte((c)[i-1]))))


Test script:
---------------
<?php

mkdir("/tmp"); // ok
mkdir("/tmp/ソフト"); // ok
touch("/tmp/ソフト/test.txt"); // ok, with warning.
echo count(stat("/tmp/ソフト/test.txt")); // FAIL

?>

Expected result:
----------------
C:\php-sdk\php54dev\vc9\x86\php5.4-201203070030>Release_TS\php.exe
\php5\test3.php
PHP Warning:  mkdir(): File exists in C:\php5\test3.php on line 3
26


run once, it creates "/tmp/ソフト/test.txt".
run one more, it won't create any more file/folder.


Actual result:
--------------
C:\php5>php.exe test3.php
PHP Warning:  mkdir(): File exists in C:\php5\test3.php on line 3
PHP Warning:  touch(): Utime failed: No such file or directory in
C:\php5\test3.php on line 5
PHP Warning:  stat(): stat failed for /tmp/ソフト/test.txt in
C:\php5\test3.php on line 6
1


run once, it creates "/tmp/ソフト/test.txt".
run one more, it creates "/tmp/ソソフト/test.txt".


-- 
Edit bug report at https://bugs.php.net/bug.php?id=61315&edit=1
-- 
Try a snapshot (PHP 5.4):            
https://bugs.php.net/fix.php?id=61315&r=trysnapshot54
Try a snapshot (PHP 5.3):            
https://bugs.php.net/fix.php?id=61315&r=trysnapshot53
Try a snapshot (trunk):              
https://bugs.php.net/fix.php?id=61315&r=trysnapshottrunk
Fixed in SVN:                        
https://bugs.php.net/fix.php?id=61315&r=fixed
Fixed in SVN and need be documented: 
https://bugs.php.net/fix.php?id=61315&r=needdocs
Fixed in release:                    
https://bugs.php.net/fix.php?id=61315&r=alreadyfixed
Need backtrace:                      
https://bugs.php.net/fix.php?id=61315&r=needtrace
Need Reproduce Script:               
https://bugs.php.net/fix.php?id=61315&r=needscript
Try newer version:                   
https://bugs.php.net/fix.php?id=61315&r=oldversion
Not developer issue:                 
https://bugs.php.net/fix.php?id=61315&r=support
Expected behavior:                   
https://bugs.php.net/fix.php?id=61315&r=notwrong
Not enough info:                     
https://bugs.php.net/fix.php?id=61315&r=notenoughinfo
Submitted twice:                     
https://bugs.php.net/fix.php?id=61315&r=submittedtwice
register_globals:                    
https://bugs.php.net/fix.php?id=61315&r=globals
PHP 4 support discontinued:          
https://bugs.php.net/fix.php?id=61315&r=php4
Daylight Savings:                    https://bugs.php.net/fix.php?id=61315&r=dst
IIS Stability:                       
https://bugs.php.net/fix.php?id=61315&r=isapi
Install GNU Sed:                     
https://bugs.php.net/fix.php?id=61315&r=gnused
Floating point limitations:          
https://bugs.php.net/fix.php?id=61315&r=float
No Zend Extensions:                  
https://bugs.php.net/fix.php?id=61315&r=nozend
MySQL Configuration Error:           
https://bugs.php.net/fix.php?id=61315&r=mysqlcfg

Reply via email to