php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #60704 unlink() bug with some files path
Submitted: 2012-01-10 19:58 UTC Modified: 2012-02-14 14:17 UTC
From: dean at dacunha dot net Assigned: shm (profile)
Status: Closed Package: Filesystem function related
PHP Version: 5.3.10 OS: Linux 3.0.0-14-generic #23-Ubunt
Private report: No CVE-ID: None
 [2012-01-10 19:58 UTC] dean at dacunha dot net
Description:
------------
unlink() function truncates the file path name argument in some cases.

This bug appears also with the rename() function in the same cases.

The given source code use link() to duplicate a file, then unlink() to remove the 
source file. link() function works and unlink() bugs.

Test script:
---------------
#!/usr/local/bin/php
<?php

$Target="/mnt/M://BRASIL/Carlinhos Brown/Alfagamabetizado - Angel's Robot List.mp3";
$Link="/mnt/M:/NEWBASE/BRASIL/Carlinhos Brown/Alfagamabetizado - Angel's Robot List.1.2.mp3";

link($Target,$Link);
unlink($Target);


?>


Expected result:
----------------
unlink() should remove the "/mnt/M://BRASIL/Carlinhos Brown/Alfagamabetizado - 
Angel's Robot List.mp3" file


Actual result:
--------------
root@djavanubu:/# ./b.php

Warning: unlink(BRASIL/Carlinhos Brown/Alfagamabetizado - Angel's Robot 
List.mp3): No such file or directory in /b.php on line 8

###################
below trace shows the truncated file path given to unlink() syscall:
[...]
lstat("/mnt/M://BRASIL", {st_mode=S_IFDIR|0755, st_size=69632, ...}) = 0
link("/mnt/M://BRASIL/Carlinhos Brown/Alfagamabetizado - Angel's Robot 
List.mp3", "/mnt/M:/NEWBASE/BRASIL/Carlinhos Brown/Alfagamabetizado - Angel's 
Robot List.1.2.mp3") = 0
unlink("BRASIL/Carlinhos Brown/Alfagamabetizado - Angel's Robot List.mp3") = -1 
ENOENT (No such file or directory)
write(1, "\nWarning: unlink(BRASIL/Carlinho"..., 130
Warning: unlink(BRASIL/Carlinhos Brown/Alfagamabetizado - Angel's Robot 
List.mp3): No such file or directory in /b.php on line 8
) = 130
[...]

Patches

themostevilpatchever2.patch (last revision 2012-02-12 09:53 UTC by shm@php.net)
themostevilpatchever.patch (last revision 2012-02-11 08:32 UTC by shm@php.net)

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2012-01-27 05:42 UTC] carloschilazo at gmail dot com
Does this happen also in 5.3.9 ?

Please confirm so I can look into it

Thanks
 [2012-01-29 02:48 UTC] rasmus@php.net
-Status: Open +Status: Feedback
 [2012-02-06 14:55 UTC] dean at dacunha dot net
-Status: Feedback +Status: Open -PHP Version: 5.3.8 +PHP Version: 5.3.10
 [2012-02-06 14:55 UTC] dean at dacunha dot net
Hi,
I've just tested with php 5.3.10, the bug is still here.
Do you still need me to test with version 5.3.9 ?

Here is the proof:

root@djavanubu:/root#
root@djavanubu:/root# cat b.php
#!/usr/local/bin/php
<?php

$Target="/mnt/M://BRASIL/Carlinhos Brown/Alfagamabetizado - Angel's Robot 
List.mp3"; $Link="/mnt/M:/NEWBASE/BRASIL/Carlinhos Brown/Alfagamabetizado - 
Angel's Robot List.1.2.mp3";

link($Target,$Link);
unlink($Target);


?>
root@djavanubu:/root#
root@djavanubu:/root# /usr/local/bin/php -v
PHP 5.3.10 (cli) (built: Jan 31 2012 22:48:16)
Copyright (c) 1997-2012 The PHP Group
Zend Engine v2.3.0, Copyright (c) 1998-2012 Zend Technologies
root@djavanubu:/root#
root@djavanubu:/root#
root@djavanubu:/root# ./b.php

Warning: unlink(BRASIL/Carlinhos Brown/Alfagamabetizado - Angel's Robot 
List.mp3): No such file or directory in /root/b.php on line 7
root@djavanubu:/root#
root@djavanubu:/root# rm "/mnt/M:/NEWBASE/BRASIL/Carlinhos 
Brown/Alfagamabetizado - Angel's Robot List.1.2.mp3"
root@djavanubu:/root#
root@djavanubu:/root# strace ./b.php
[...]
lstat("/mnt/M://BRASIL/Carlinhos Brown/Alfagamabetizado - Angel's Robot 
List.mp3", {st_mode=S_IFREG|0755, st_size=1247232, ...}) = 0
lstat("/mnt/M://BRASIL/Carlinhos Brown", {st_mode=S_IFDIR|0755, st_size=40960, 
...}) = 0
lstat("/mnt/M://BRASIL", {st_mode=S_IFDIR|0755, st_size=81920, ...}) = 0
link("/mnt/M://BRASIL/Carlinhos Brown/Alfagamabetizado - Angel's Robot 
List.mp3", "/mnt/M:/NEWBASE/BRASIL/Carlinhos Brown/Alfagamabetizado - Angel's 
Robot List.1.2.mp3") = 0
unlink("BRASIL/Carlinhos Brown/Alfagamabetizado - Angel's Robot List.mp3") = -1 
ENOENT (No such file or directory)
write(1, "\nWarning: unlink(BRASIL/Carlinho"..., 135
Warning: unlink(BRASIL/Carlinhos Brown/Alfagamabetizado - Angel's Robot 
List.mp3): No such file or directory in /root/b.php on line 7
) = 135
[...]
 [2012-02-11 08:19 UTC] shm@php.net
-Assigned To: +Assigned To: shm
 [2012-02-11 08:32 UTC] shm@php.net
The following patch has been added/updated:

Patch Name: themostevilpatchever.patch
Revision:   1328949124
URL:        https://bugs.php.net/patch-display.php?bug=60704&patch=themostevilpatchever.patch&revision=1328949124
 [2012-02-11 08:32 UTC] shm@php.net
Attached patch should fix this issue. Will commit if after a review.
 [2012-02-12 09:53 UTC] shm@php.net
The following patch has been added/updated:

Patch Name: themostevilpatchever2.patch
Revision:   1329040416
URL:        https://bugs.php.net/patch-display.php?bug=60704&patch=themostevilpatchever2.patch&revision=1329040416
 [2012-02-14 14:14 UTC] shm@php.net
Automatic comment from SVN on behalf of shm
Revision: http://svn.php.net/viewvc/?view=revision&amp;revision=323213
Log: * fixed bug #60704 unlink() bug with some files path

Reviewed by: rasmus@
 [2012-02-14 14:17 UTC] shm@php.net
This bug has been fixed in SVN.

Snapshots of the sources are packaged every three hours; this change
will be in the next snapshot. You can grab the snapshot at
http://snaps.php.net/.

 For Windows:

http://windows.php.net/snapshots/
 
Thank you for the report, and for helping us make PHP better.


 [2012-02-14 14:17 UTC] shm@php.net
-Status: Assigned +Status: Closed
 [2012-04-18 09:46 UTC] laruence@php.net
Automatic comment on behalf of shm
Revision: http://git.php.net/?p=php-src.git;a=commit;h=4d600bda7083ebaeb71d94b0fb6df3a760268d45
Log: * fixed bug #60704 unlink() bug with some files path
 [2012-07-24 23:37 UTC] rasmus@php.net
Automatic comment on behalf of shm
Revision: http://git.php.net/?p=php-src.git;a=commit;h=4d600bda7083ebaeb71d94b0fb6df3a760268d45
Log: * fixed bug #60704 unlink() bug with some files path
 [2013-11-17 09:33 UTC] laruence@php.net
Automatic comment on behalf of shm
Revision: http://git.php.net/?p=php-src.git;a=commit;h=4d600bda7083ebaeb71d94b0fb6df3a760268d45
Log: * fixed bug #60704 unlink() bug with some files path
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Thu Nov 21 09:01:32 2024 UTC