From 8fe79305331f12852afe2137a01fda373d8b37cb Mon Sep 17 00:00:00 2001 From: Niels Dossche <7771979+ndossche@users.noreply.github.com> Date: Tue, 25 Nov 2025 23:11:38 +0100 Subject: [PATCH] Fix GH-20584: Information Leak of Memory The string added had uninitialized memory due to php_read_stream_all_chunks() not moving the buffer position, resulting in the same data always being overwritten instead of new data being added to the end of the buffer. Closes GH-20592. --- NEWS | 1 + ext/standard/image.c | 1 + ext/standard/tests/image/gh20584.phpt | 39 +++++++++++++++++++++++++++ 3 files changed, 41 insertions(+) create mode 100644 ext/standard/tests/image/gh20584.phpt diff --git a/NEWS b/NEWS index b87cba17aad..863d672d736 100644 --- a/NEWS +++ b/NEWS @@ -60,6 +60,7 @@ PHP NEWS . Fix memory leak in array_diff() with custom type checks. (ndossche) . Fixed bug GH-20583 (Stack overflow in http_build_query via deep structures). (ndossche) + . Fixed bug GH-20584 (Information Leak of Memory). (ndossche) - Tidy: . Fixed bug GH-20374 (PHP with tidy and custom-tags). (ndossche) diff --git a/ext/standard/image.c b/ext/standard/image.c index 2bd5429efac..15761364c34 100644 --- a/ext/standard/image.c +++ b/ext/standard/image.c @@ -403,6 +403,7 @@ static size_t php_read_stream_all_chunks(php_stream *stream, char *buffer, size_ if (read_now < stream->chunk_size && read_total != length) { return 0; } + buffer += read_now; } while (read_total < length); return read_total; diff --git a/ext/standard/tests/image/gh20584.phpt b/ext/standard/tests/image/gh20584.phpt new file mode 100644 index 00000000000..d117f218202 --- /dev/null +++ b/ext/standard/tests/image/gh20584.phpt @@ -0,0 +1,39 @@ +--TEST-- +GH-20584 (Information Leak of Memory) +--CREDITS-- +Nikita Sveshnikov (Positive Technologies) +--FILE-- + +--CLEAN-- + +--EXPECT-- +bool(true)