Copying a file into itself leads to data loss
| 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 commits
[2005-06-22 18:14 UTC] iliaa@php.net
[2005-06-27 01:19 UTC] tony2001@php.net
[2005-07-20 21:26 UTC] iliaa@php.net