From dc7aa22b18b710aaa837c9466e9a77241f909c8a Mon Sep 17 00:00:00 2001 From: Albert Casademont Date: Tue, 23 Jul 2019 14:03:06 +0200 Subject: [PATCH] Fix bug #78326 Similar to what fread() does, truncate the stream_get_contents() result if the original buffer was way too large. --- NEWS | 2 ++ ext/standard/tests/streams/bug78326.phpt | 18 ++++++++++++++++++ ext/standard/tests/streams/bug78326_1.phpt | 10 ++++++++++ main/streams/streams.c | 7 ++++++- 4 files changed, 36 insertions(+), 1 deletion(-) create mode 100644 ext/standard/tests/streams/bug78326.phpt create mode 100644 ext/standard/tests/streams/bug78326_1.phpt diff --git a/NEWS b/NEWS index d76ee3c55a3..d8181a70282 100644 --- a/NEWS +++ b/NEWS @@ -20,6 +20,8 @@ PHP NEWS - Standard: . Fixed bug #69100 (Bus error from stream_copy_to_stream (file -> SSL stream) with invalid length). (Nikita) + . Fixed bug #78326 (improper memory deallocation on stream_get_contents() + with fixed length buffer). (Albert Casademont) 01 Aug 2019, PHP 7.2.21 diff --git a/ext/standard/tests/streams/bug78326.phpt b/ext/standard/tests/streams/bug78326.phpt new file mode 100644 index 00000000000..ca27b05f62a --- /dev/null +++ b/ext/standard/tests/streams/bug78326.phpt @@ -0,0 +1,18 @@ +--TEST-- +memory allocation on stream_get_contents() +--INI-- +memory_limit=32M +--FILE-- + +--EXPECT-- +int(1000) diff --git a/ext/standard/tests/streams/bug78326_1.phpt b/ext/standard/tests/streams/bug78326_1.phpt new file mode 100644 index 00000000000..8e3489db535 --- /dev/null +++ b/ext/standard/tests/streams/bug78326_1.phpt @@ -0,0 +1,10 @@ +--TEST-- +proper string length on stream_get_contents() +--FILE-- +