fix #35781 (stream_filter_append() can cause segfault)

This commit is contained in:
Antony Dovgal 2005-12-23 14:32:11 +00:00
parent cf90abfc24
commit 248be6fcfc
3 changed files with 27 additions and 3 deletions

View 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

View File

@ -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

View File

@ -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;
}
}