Bug #71630 [NEW]: copy function does not work if destination file does not exist
From: vladimir at volomp dot com
Operating system: linux/all
PHP version: 5.5.32
Package: *General Issues
Bug Type: Bug
Bug description:copy function does not work if destination file does not exist
Description:
------------
Fails to copy a.txt to b.txt if b.txt is missing.
If we just touch b.txt, copy will work.
There is possibly relevant code in ext/standard/file.c in function
php_copy_file_ctx() where dest is checked the same way source is
(suspected copy&paste).
switch (php_stream_stat_path_ex(dest, PHP_STREAM_URL_STAT_QUIET
| PHP_STREAM_URL_STAT_NOCACHE, &dest_s, ctx)) {
case -1:
/* non-statable stream */
goto safe_to_copy;
break;
case 0:
break;
default: /* failed to stat file, does not exist? */
return ret;
}
So it is unclear if PHP_STREAM_URL_STAT_QUIET has any influence on
return code - but I guess NO, so then this block of code is incorrect
and should have default goto safe_to_copy.
This code is more-less same for php 5.6 and 7, however 5.2.17 which we
still use do not have this bug as check is done differently:
if (php_stream_stat_path_ex(dest, PHP_STREAM_URL_STAT_QUIET,
&dest_s, NULL) != 0) {
goto safe_to_copy;
}
Test script:
---------------
copy( "a.txt", "b.txt" );
--
Edit bug report at https://bugs.php.net/bug.php?id=71630&edit=1
--
Try a snapshot (PHP 5.4): https://bugs.php.net/fix.php?id=71630&r=trysnapshot54
Try a snapshot (PHP 5.5): https://bugs.php.net/fix.php?id=71630&r=trysnapshot55
Try a snapshot (trunk): https://bugs.php.net/fix.php?id=71630&r=trysnapshottrunk
Fixed in SVN: https://bugs.php.net/fix.php?id=71630&r=fixed
Fixed in release: https://bugs.php.net/fix.php?id=71630&r=alreadyfixed
Need backtrace: https://bugs.php.net/fix.php?id=71630&r=needtrace
Need Reproduce Script: https://bugs.php.net/fix.php?id=71630&r=needscript
Try newer version: https://bugs.php.net/fix.php?id=71630&r=oldversion
Not developer issue: https://bugs.php.net/fix.php?id=71630&r=support
Expected behavior: https://bugs.php.net/fix.php?id=71630&r=notwrong
Not enough info: https://bugs.php.net/fix.php?id=71630&r=notenoughinfo
Submitted twice: https://bugs.php.net/fix.php?id=71630&r=submittedtwice
register_globals: https://bugs.php.net/fix.php?id=71630&r=globals
PHP 4 support discontinued: https://bugs.php.net/fix.php?id=71630&r=php4
Daylight Savings: https://bugs.php.net/fix.php?id=71630&r=dst
IIS Stability: https://bugs.php.net/fix.php?id=71630&r=isapi
Install GNU Sed: https://bugs.php.net/fix.php?id=71630&r=gnused
Floating point limitations: https://bugs.php.net/fix.php?id=71630&r=float
No Zend Extensions: https://bugs.php.net/fix.php?id=71630&r=nozend
MySQL Configuration Error: https://bugs.php.net/fix.php?id=71630&r=mysqlcfg
Thread (9 messages)
- vladimir at volomp dot com