mirror of
https://github.com/php/php-src.git
synced 2024-11-23 18:04:36 +08:00
fix #35781 (stream_filter_append() can cause segfault)
This commit is contained in:
parent
cf90abfc24
commit
248be6fcfc
24
ext/standard/tests/file/bug35781.phpt
Normal file
24
ext/standard/tests/file/bug35781.phpt
Normal file
@ -0,0 +1,24 @@
|
||||
--TEST--
|
||||
Bug #35781 (stream_filter_append() causes segfault)
|
||||
--FILE--
|
||||
<?php
|
||||
|
||||
$filename = dirname(__FILE__)."/bug35781.txt";
|
||||
|
||||
$fp = fopen($filename, "w");
|
||||
stream_filter_append($fp, "string.rot13", -49);
|
||||
fwrite($fp, "This is a test\n");
|
||||
rewind($fp);
|
||||
fpassthru($fp);
|
||||
fclose($fp);
|
||||
|
||||
var_dump(file_get_contents($filename));
|
||||
|
||||
@unlink($filename);
|
||||
|
||||
echo "Done\n";
|
||||
?>
|
||||
--EXPECTF--
|
||||
string(15) "Guvf vf n grfg
|
||||
"
|
||||
Done
|
@ -316,7 +316,7 @@ static size_t php_stdiop_read(php_stream *stream, char *buf, size_t count TSRMLS
|
||||
if (data->fd >= 0) {
|
||||
ret = read(data->fd, buf, count);
|
||||
|
||||
stream->eof = (ret == 0 || (ret == -1 && errno != EWOULDBLOCK));
|
||||
stream->eof = (ret == 0 || (ret == (size_t)-1 && errno != EWOULDBLOCK));
|
||||
|
||||
} else {
|
||||
#if HAVE_FLUSHIO
|
||||
|
@ -442,7 +442,7 @@ static void php_stream_fill_read_buffer(php_stream *stream, size_t size TSRMLS_D
|
||||
|
||||
/* read a chunk into a bucket */
|
||||
justread = stream->ops->read(stream, chunk_buf, stream->chunk_size TSRMLS_CC);
|
||||
if (justread > 0) {
|
||||
if (justread != (size_t)-1) {
|
||||
bucket = php_stream_bucket_new(stream, chunk_buf, justread, 0, 0 TSRMLS_CC);
|
||||
|
||||
/* after this call, bucket is owned by the brigade */
|
||||
@ -511,7 +511,7 @@ static void php_stream_fill_read_buffer(php_stream *stream, size_t size TSRMLS_D
|
||||
break;
|
||||
}
|
||||
|
||||
if (justread == 0) {
|
||||
if (justread == 0 || justread == (size_t)-1) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user