mirror of
https://github.com/php/php-src.git
synced 2024-11-28 04:14:26 +08:00
Merge branch 'PHP-7.3'
* PHP-7.3: Fixed bug #76803 ftruncate changes file pointer
This commit is contained in:
commit
8b4b41696e
38
ext/standard/tests/file/ftruncate_bug76803.phpt
Normal file
38
ext/standard/tests/file/ftruncate_bug76803.phpt
Normal file
@ -0,0 +1,38 @@
|
||||
--TEST--
|
||||
Bug #76803 ftruncate changes file pointer
|
||||
--FILE--
|
||||
<?php
|
||||
|
||||
$fn = dirname(__FILE__) . DIRECTORY_SEPARATOR . "test76803";
|
||||
|
||||
$f = fopen($fn, "w");
|
||||
fwrite($f, "Hello");
|
||||
ftruncate($f, 2);
|
||||
fwrite($f, "World");
|
||||
fclose($f);
|
||||
var_dump(addslashes(file_get_contents($fn)));
|
||||
|
||||
$f = fopen($fn, "w");
|
||||
fwrite($f, "Hello");
|
||||
ftruncate($f, 2);
|
||||
fclose($f);
|
||||
var_dump(addslashes(file_get_contents($fn)));
|
||||
|
||||
$f = fopen('php://memory', 'w+');
|
||||
fwrite($f, 'Hello');
|
||||
ftruncate($f, 2); // in 7.3 changes file pointer to 2
|
||||
fwrite($f, 'World');
|
||||
rewind($f);
|
||||
var_dump(addslashes(stream_get_contents($f)));
|
||||
fclose($f);
|
||||
|
||||
?>
|
||||
--CLEAN--
|
||||
<?php
|
||||
$fn = dirname(__FILE__) . DIRECTORY_SEPARATOR . "test76803";
|
||||
unlink($fn);
|
||||
?>
|
||||
--EXPECT--
|
||||
string(13) "He\0\0\0World"
|
||||
string(2) "He"
|
||||
string(7) "HeWorld"
|
@ -857,6 +857,12 @@ static int php_stdiop_set_option(php_stream *stream, int option, int value, void
|
||||
if (INVALID_HANDLE_VALUE == h) {
|
||||
return PHP_STREAM_OPTION_RETURN_ERR;
|
||||
}
|
||||
|
||||
LARGE_INTEGER old_sz;
|
||||
if (!GetFileSizeEx(h, &old_sz)) {
|
||||
return PHP_STREAM_OPTION_RETURN_ERR;
|
||||
}
|
||||
|
||||
LARGE_INTEGER sz;
|
||||
#if defined(_WIN64)
|
||||
sz.HighPart = (new_size >> 32);
|
||||
@ -871,6 +877,9 @@ static int php_stdiop_set_option(php_stream *stream, int option, int value, void
|
||||
if (0 == SetEndOfFile(h)) {
|
||||
return PHP_STREAM_OPTION_RETURN_ERR;
|
||||
}
|
||||
if (INVALID_SET_FILE_POINTER == SetFilePointerEx(h, old_sz, NULL, FILE_BEGIN) && NO_ERROR != GetLastError()) {
|
||||
return PHP_STREAM_OPTION_RETURN_ERR;
|
||||
}
|
||||
return PHP_STREAM_OPTION_RETURN_OK;
|
||||
#else
|
||||
return ftruncate(fd, new_size) == 0 ? PHP_STREAM_OPTION_RETURN_OK : PHP_STREAM_OPTION_RETURN_ERR;
|
||||
|
Loading…
Reference in New Issue
Block a user