|  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
Status: Closed Package: Filesystem function related
PHP Version: 4CVS-2005-06-20 OS: *
Private report: No CVE-ID:
 [2005-03-02 03:20 UTC] chernyshevsky at hotmail dot com
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.


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2005-06-22 18:14 UTC]
Fixed in PHP5 CVS, will be applied to 4.X tree after 4.4 release.
 [2005-06-27 01:19 UTC]
Assigned to Ilia so he won't forget to commit it after 4.4 release.
 [2005-07-20 21:26 UTC]
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
Thank you for the report, and for helping us make PHP better.

PHP Copyright © 2001-2015 The PHP Group
All rights reserved.
Last updated: Fri Oct 09 06:02:00 2015 UTC