Skip to content

Commit 774f163

Browse files
committed
Merge branch 'PHP-5.5' into PHP-5.6
* PHP-5.5: Fix bug #65701: Do not use cache for file file copy
2 parents 1bca3ec + 5addf22 commit 774f163

File tree

5 files changed

+61
-26
lines changed

5 files changed

+61
-26
lines changed

NEWS

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@ PHP NEWS
88
- Core:
99
. Fixed bug #64604 (parse_url is inconsistent with specified port).
1010
(Ingo Walz)
11+
. Fixed bug #65701 (copy() doesn't work when destination filename is created
12+
by tempnam()). (Boro Sitnikovski)
1113
. Fixed bug #66015 (Unexpected array indexing in class's static property). (Bob)
1214
. Added (constant) string/array dereferencing to static scalar expressions
1315
to complete the set; now possible thanks to bug #66015 being fixed. (Bob)
@@ -18,6 +20,7 @@ PHP NEWS
1820
height). (Gabor Buella)
1921
. Fixed bug #67064 (Countable interface prevents using 2nd parameter
2022
($mode) of count() function). (Bob)
23+
. Fixed bug #67072 (Echoing unserialized "SplFileObject" crash). (Anatol)
2124

2225
- cURL:
2326
. Fixed bug #66562 (curl_exec returns differently than curl_multi_getcontent).
@@ -59,9 +62,6 @@ PHP NEWS
5962
- SQLite:
6063
. Fixed bug #66967 (Updated bundled libsqlite to 3.8.4.3). (Anatol)
6164

62-
- Standard:
63-
. Fixed bug #67072 (Echoing unserialized "SplFileObject" crash). (Anatol)
64-
6565
- Apache2 Handler SAPI:
6666
. Fixed Apache log issue caused by APR's lack of support for %zu
6767
(APR issue https://issues.apache.org/bugzilla/show_bug.cgi?id=56120).

ext/standard/file.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1668,7 +1668,7 @@ PHPAPI int php_copy_file_ctx(const char *src, const char *dest, int src_flg, php
16681668
return FAILURE;
16691669
}
16701670

1671-
switch (php_stream_stat_path_ex(dest, PHP_STREAM_URL_STAT_QUIET, &dest_s, ctx)) {
1671+
switch (php_stream_stat_path_ex(dest, PHP_STREAM_URL_STAT_QUIET | PHP_STREAM_URL_STAT_NOCACHE, &dest_s, ctx)) {
16721672
case -1:
16731673
/* non-statable stream */
16741674
goto safe_to_copy;

ext/standard/tests/file/bug65701.phpt

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
--TEST--
2+
Test for bug #65701: copy() doesn't work when destination filename is created by tempnam()
3+
--CREDITS--
4+
Boro Sitnikovski <buritomath@yahoo.com>
5+
--FILE--
6+
<?php
7+
$file_path = dirname(__FILE__) . "/bug65701/";
8+
9+
mkdir($file_path);
10+
11+
$src = $file_path . '/srcbug65701_file.txt';
12+
$dst = tempnam($file_path, 'dstbug65701_file.txt');
13+
14+
file_put_contents($src, "Hello World");
15+
16+
copy($src, $dst);
17+
var_dump(filesize($dst));
18+
?>
19+
--CLEAN--
20+
<?php
21+
$file_path = dirname(__FILE__) . "/bug65701/";
22+
foreach (scandir($file_path) as $file) {
23+
if (strpos($file, "bug65701") !== false) {
24+
unlink($file_path . $file);
25+
}
26+
}
27+
rmdir($file_path);
28+
?>
29+
--EXPECT--
30+
int(11)

main/php_streams.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -373,6 +373,7 @@ END_EXTERN_C()
373373
/* Flags for url_stat method in wrapper ops */
374374
#define PHP_STREAM_URL_STAT_LINK 1
375375
#define PHP_STREAM_URL_STAT_QUIET 2
376+
#define PHP_STREAM_URL_STAT_NOCACHE 4
376377

377378
/* change the blocking mode of stream: value == 1 => blocking, value == 0 => non-blocking. */
378379
#define PHP_STREAM_OPTION_BLOCKING 1

main/streams/streams.c

Lines changed: 26 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1924,36 +1924,40 @@ PHPAPI int _php_stream_stat_path(const char *path, int flags, php_stream_statbuf
19241924
const char *path_to_open = path;
19251925
int ret;
19261926

1927-
/* Try to hit the cache first */
1928-
if (flags & PHP_STREAM_URL_STAT_LINK) {
1929-
if (BG(CurrentLStatFile) && strcmp(path, BG(CurrentLStatFile)) == 0) {
1930-
memcpy(ssb, &BG(lssb), sizeof(php_stream_statbuf));
1931-
return 0;
1932-
}
1933-
} else {
1934-
if (BG(CurrentStatFile) && strcmp(path, BG(CurrentStatFile)) == 0) {
1935-
memcpy(ssb, &BG(ssb), sizeof(php_stream_statbuf));
1936-
return 0;
1927+
if (!(flags & PHP_STREAM_URL_STAT_NOCACHE)) {
1928+
/* Try to hit the cache first */
1929+
if (flags & PHP_STREAM_URL_STAT_LINK) {
1930+
if (BG(CurrentLStatFile) && strcmp(path, BG(CurrentLStatFile)) == 0) {
1931+
memcpy(ssb, &BG(lssb), sizeof(php_stream_statbuf));
1932+
return 0;
1933+
}
1934+
} else {
1935+
if (BG(CurrentStatFile) && strcmp(path, BG(CurrentStatFile)) == 0) {
1936+
memcpy(ssb, &BG(ssb), sizeof(php_stream_statbuf));
1937+
return 0;
1938+
}
19371939
}
19381940
}
19391941

19401942
wrapper = php_stream_locate_url_wrapper(path, &path_to_open, 0 TSRMLS_CC);
19411943
if (wrapper && wrapper->wops->url_stat) {
19421944
ret = wrapper->wops->url_stat(wrapper, path_to_open, flags, ssb, context TSRMLS_CC);
19431945
if (ret == 0) {
1944-
/* Drop into cache */
1945-
if (flags & PHP_STREAM_URL_STAT_LINK) {
1946-
if (BG(CurrentLStatFile)) {
1947-
efree(BG(CurrentLStatFile));
1948-
}
1949-
BG(CurrentLStatFile) = estrdup(path);
1950-
memcpy(&BG(lssb), ssb, sizeof(php_stream_statbuf));
1951-
} else {
1952-
if (BG(CurrentStatFile)) {
1953-
efree(BG(CurrentStatFile));
1946+
if (!(flags & PHP_STREAM_URL_STAT_NOCACHE)) {
1947+
/* Drop into cache */
1948+
if (flags & PHP_STREAM_URL_STAT_LINK) {
1949+
if (BG(CurrentLStatFile)) {
1950+
efree(BG(CurrentLStatFile));
1951+
}
1952+
BG(CurrentLStatFile) = estrdup(path);
1953+
memcpy(&BG(lssb), ssb, sizeof(php_stream_statbuf));
1954+
} else {
1955+
if (BG(CurrentStatFile)) {
1956+
efree(BG(CurrentStatFile));
1957+
}
1958+
BG(CurrentStatFile) = estrdup(path);
1959+
memcpy(&BG(ssb), ssb, sizeof(php_stream_statbuf));
19541960
}
1955-
BG(CurrentStatFile) = estrdup(path);
1956-
memcpy(&BG(ssb), ssb, sizeof(php_stream_statbuf));
19571961
}
19581962
}
19591963
return ret;

0 commit comments

Comments
 (0)