[php-src] PHP-8.3: Merge branch 'PHP-8.2' into PHP-8.3
| From: | Jakub Zelenka | Date: | Fri, 29 Mar 2024 16:09:21 +0000 |
| Subject: | [php-src] PHP-8.3: Merge branch 'PHP-8.2' into PHP-8.3 | ||
| Groups: | php.cvs | ||
| Request: | Send a blank email to php-cvs+get-127880@lists.php.net to get a copy of this message | ||
Author: Jakub Zelenka (bukka)
Date: 2024-03-29T16:09:09Z
Commit: https://github.com/php/php-src/commit/caec2b6186fe7c87f20b098acbc105346075995d
Raw diff: https://github.com/php/php-src/commit/caec2b6186fe7c87f20b098acbc105346075995d.diff
Merge branch 'PHP-8.2' into PHP-8.3
Changed paths:
A ext/standard/tests/filters/gh13264.phpt
M NEWS
M ext/standard/user_filters.c
M main/streams/streams.c
Diff:
diff --git a/NEWS b/NEWS
index 361a896d8d0b4..55367865c240c 100644
--- a/NEWS
+++ b/NEWS
@@ -2,10 +2,18 @@ PHP NEWS
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
?? ??? ????, PHP 8.3.6
+- FPM:
+ . Fixed bug GH-13563 (Setting bool values via env in FPM config fails).
+ (Jakub Zelenka)
+
- Opcache:
. Fixed bug GH-13433 (Segmentation Fault in zend_class_init_statics when
using opcache.preload). (nielsdos)
+- Streams:
+ . Fixed bug GH-13264 (Part 1 - Memory leak on stream filter failure).
+ (Jakub Zelenka)
+
28 Mar 2024, PHP 8.3.5RC1
- Core:
@@ -26,8 +34,6 @@ PHP NEWS
. Fixed GH-11086 (FPM: config test runs twice in daemonised mode).
(Jakub Zelenka)
. Fixed incorrect check in fpm_shm_free(). (nielsdos)
- . Fixed bug GH-13563 (Setting bool values via env in FPM config fails).
- (Jakub Zelenka)
- GD:
. Fixed bug GH-12019 (add GDLIB_CFLAGS in feature tests). (Michael Orlitzky)
diff --git a/ext/standard/tests/filters/gh13264.phpt b/ext/standard/tests/filters/gh13264.phpt
new file mode 100644
index 0000000000000..6456a082a1e40
--- /dev/null
+++ b/ext/standard/tests/filters/gh13264.phpt
@@ -0,0 +1,49 @@
+--TEST--
+GH-81475: Memory leak during stream filter failure
+--SKIPIF--
+<?php require 'filter_errors.inc'; filter_errors_skipif('zlib.inflate');
?>
+--FILE--
+<?php
+// Prepare a big enough input so that it is not entirely buffered
+$stream = fopen('php://memory', 'r+');
+$content = '';
+for ($i = 0; $i < 10000; $i++) {
+ $content .= "Hello $i\n";
+}
+fwrite($stream, gzcompress($content));
+
+// Mess up the checksum
+fseek($stream, -1, SEEK_CUR);
+fwrite($stream, '1');
+
+// Rewind and add the zlib filter
+rewind($stream);
+stream_filter_append($stream, 'zlib.inflate', STREAM_FILTER_READ, ['window'
=> 15]);
+
+// Read the filtered stream line by line.
+while (($line = fgets($stream)) !== false) {
+ $error = error_get_last();
+ if ($error !== null) {
+ // An error is thrown but fgets didn't return false
+ var_dump(error_get_last());
+ var_dump($line);
+ }
+}
+
+fclose($stream);
+?>
+--EXPECTF--
+
+Notice: fgets(): zlib: data error in %s on line %d
+array(4) {
+ ["type"]=>
+ int(8)
+ ["message"]=>
+ string(25) "fgets(): zlib: data error"
+ ["file"]=>
+ string(%d) "%s"
+ ["line"]=>
+ int(%d)
+}
+string(7) "Hello 6"
+
diff --git a/ext/standard/user_filters.c b/ext/standard/user_filters.c
index adfec58e8dbee..063895e2f4049 100644
--- a/ext/standard/user_filters.c
+++ b/ext/standard/user_filters.c
@@ -190,22 +190,7 @@ php_stream_filter_status_t userfilter_filter(
}
if (buckets_in->head) {
- php_stream_bucket *bucket;
-
php_error_docref(NULL, E_WARNING, "Unprocessed filter buckets remaining on input
brigade");
- while ((bucket = buckets_in->head)) {
- /* Remove unconsumed buckets from the brigade */
- php_stream_bucket_unlink(bucket);
- php_stream_bucket_delref(bucket);
- }
- }
- if (ret != PSFS_PASS_ON) {
- php_stream_bucket *bucket = buckets_out->head;
- while (bucket != NULL) {
- php_stream_bucket_unlink(bucket);
- php_stream_bucket_delref(bucket);
- bucket = buckets_out->head;
- }
}
/* filter resources are cleaned up by the stream destructor,
diff --git a/main/streams/streams.c b/main/streams/streams.c
index 9f79821f0c9ff..65ec69bffce14 100644
--- a/main/streams/streams.c
+++ b/main/streams/streams.c
@@ -636,6 +636,17 @@ PHPAPI zend_result _php_stream_fill_read_buffer(php_stream *stream, size_t
size)
/* some fatal error. Theoretically, the stream is borked, so all
* further reads should fail. */
stream->eof = 1;
+ /* free all data left in brigades */
+ while ((bucket = brig_inp->head)) {
+ /* Remove unconsumed buckets from the input brigade */
+ php_stream_bucket_unlink(bucket);
+ php_stream_bucket_delref(bucket);
+ }
+ while ((bucket = brig_outp->head)) {
+ /* Remove unconsumed buckets from the output brigade */
+ php_stream_bucket_unlink(bucket);
+ php_stream_bucket_delref(bucket);
+ }
efree(chunk_buf);
retval = FAILURE;
goto out_is_eof;