--- /dev/null
+--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
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
/* 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 */
break;
}
- if (justread == 0) {
+ if (justread == 0 || justread == (size_t)-1) {
break;
}
}