php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #32160 Copying a file into itself leads to data loss
Submitted: 2005-03-02 03:20 UTC Modified: 2005-07-20 21:26 UTC
From: chernyshevsky at hotmail dot com Assigned: iliaa (profile)
Status: Closed Package: Filesystem function related
PHP Version: 4CVS-2005-06-20 OS: *
Private report: No CVE-ID: None
 [2005-03-02 03:20 UTC] chernyshevsky at hotmail dot com
Description:
------------
Copying a file into itself causes the source file to be truncate to 0 bytes.

copy("test", "test"); // test.txt -> 0

You can't avoid this problem just by comparing the filenames, since one could be a symlink pointing to the other. The following would destroy test1 if test2 is a link to test1:

copy("test1", "test2");



Reproduce code:
---------------
copy("test", "test");


Expected result:
----------------
Nothing happens or a file open error.

Actual result:
--------------
Contents in source file is lost.

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2005-06-22 18:14 UTC] iliaa@php.net
Fixed in PHP5 CVS, will be applied to 4.X tree after 4.4 release.
 [2005-06-27 01:19 UTC] tony2001@php.net
Assigned to Ilia so he won't forget to commit it after 4.4 release.
 [2005-07-20 21:26 UTC] iliaa@php.net
This bug has been fixed in CVS.

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/.
 
Thank you for the report, and for helping us make PHP better.


 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Thu Nov 21 09:01:32 2024 UTC