Bug #70362 [NEW]: copy() not work with 'data://' and open_basedir if bigger than MAXPATHLEN
| From: | prochazkapp at gmail dot com | Date: | Wed, 26 Aug 2015 16:04:23 +0000 |
| Subject: | Bug #70362 [NEW]: copy() not work with 'data://' and open_basedir if bigger than MAXPATHLEN | ||
| Groups: | php.bugs | ||
| Request: | Send a blank email to php-bugs+get-195536@lists.php.net to get a copy of this message | ||
From: prochazkapp at gmail dot com
Operating system:
PHP version: Irrelevant
Package: Filesystem function related
Bug Type: Bug
Bug description:copy() not work with 'data://' and open_basedir if bigger than MAXPATHLEN
Description:
------------
If open_basedir is enabled, 'data://' wrapper does not work correctly
with copy() for data bigger than MAXPATHLEN.
I found this bug in php 5.5.21 but it affects all versions (even 7).
See https://3v4l.org/5h1aI
Here is why:
copy() calls php_check_open_basedir
https://github.com/php/php-src/blob/PHP-5.5.21/ext/standard/file.c#L1618
And this checks source len end trigger error.
https://github.com/php/php-src/blob/PHP-5.5.21/main/fopen_wrappers.c#L303
But source len is not relevant for e.g. 'data://' wrapper (and possible
some other wrappers).
This seems fixed in some other file functions:
https://github.com/php/php-src/blob/PHP-5.5.21/ext/standard/filestat.c#L867
If data:// wrapper is not intended to work with copy, it should be
mentioned in docs, but function works otherwise perfectly with disabled
open_basedir or for smaller data.
This may be related to https://bugs.php.net/bug.php?id=60456 but I
believe it's not duplicate.
Test script:
---------------
<?php
ini_set('open_basedir', '/');
$temp = tempnam(__DIR__, 'test');
$data = str_repeat('0', PHP_MAXPATHLEN * 2);
$data = 'data://plain/text;base64,' . base64_encode($data);
var_dump(copy($data, $temp));
Expected result:
----------------
bool(true)
Actual result:
--------------
Warning: copy(): File name is longer than the maximum allowed path
length on this platform (4096): data:plain/text;base64,... in ... on
line 6
bool(false)
--
Edit bug report at https://bugs.php.net/bug.php?id=70362&edit=1
--
Try a snapshot (PHP 5.4): https://bugs.php.net/fix.php?id=70362&r=trysnapshot54
Try a snapshot (PHP 5.5): https://bugs.php.net/fix.php?id=70362&r=trysnapshot55
Try a snapshot (trunk): https://bugs.php.net/fix.php?id=70362&r=trysnapshottrunk
Fixed in SVN: https://bugs.php.net/fix.php?id=70362&r=fixed
Fixed in release: https://bugs.php.net/fix.php?id=70362&r=alreadyfixed
Need backtrace: https://bugs.php.net/fix.php?id=70362&r=needtrace
Need Reproduce Script: https://bugs.php.net/fix.php?id=70362&r=needscript
Try newer version: https://bugs.php.net/fix.php?id=70362&r=oldversion
Not developer issue: https://bugs.php.net/fix.php?id=70362&r=support
Expected behavior: https://bugs.php.net/fix.php?id=70362&r=notwrong
Not enough info: https://bugs.php.net/fix.php?id=70362&r=notenoughinfo
Submitted twice: https://bugs.php.net/fix.php?id=70362&r=submittedtwice
register_globals: https://bugs.php.net/fix.php?id=70362&r=globals
PHP 4 support discontinued: https://bugs.php.net/fix.php?id=70362&r=php4
Daylight Savings: https://bugs.php.net/fix.php?id=70362&r=dst
IIS Stability: https://bugs.php.net/fix.php?id=70362&r=isapi
Install GNU Sed: https://bugs.php.net/fix.php?id=70362&r=gnused
Floating point limitations: https://bugs.php.net/fix.php?id=70362&r=float
No Zend Extensions: https://bugs.php.net/fix.php?id=70362&r=nozend
MySQL Configuration Error: https://bugs.php.net/fix.php?id=70362&r=mysqlcfg