]> granicus.if.org Git - php/commitdiff
Fixed bug #78612
authorNikita Popov <nikita.ppv@gmail.com>
Mon, 30 Sep 2019 13:05:35 +0000 (15:05 +0200)
committerNikita Popov <nikita.ppv@gmail.com>
Mon, 30 Sep 2019 13:06:07 +0000 (15:06 +0200)
NEWS
ext/standard/string.c
ext/standard/tests/strings/bug78612.phpt [new file with mode: 0644]

diff --git a/NEWS b/NEWS
index 89a65dd49e7ba0d549f886b57481d02f4c2ebb25..1c4ce6fe5d88cf61eaa19be5ba24e8f5152d7770 100644 (file)
--- a/NEWS
+++ b/NEWS
@@ -19,6 +19,8 @@ PHP                                                                        NEWS
 - Standard:
   . Fixed bug #76342 (file_get_contents waits twice specified timeout).
     (Thomas Calvet)
+  . Fixed bug #78612 (strtr leaks memory when integer keys are used and the
+    subject string shorter). (Nikita)
 
 26 Sep 2019, PHP 7.2.23
 
index 2907c2253b26a496ceb6ec8fb20abf9c76484a8c..dcf9cb44c76b6546de6734278e76b59e8aa747eb 100644 (file)
@@ -3027,6 +3027,7 @@ static void php_strtr_array(zval *return_value, zend_string *input, HashTable *p
                                len = ZSTR_LEN(key_used);
                                if (UNEXPECTED(len > slen)) {
                                        /* skip long patterns */
+                                       zend_string_release(key_used);
                                        continue;
                                }
                                if (len > maxlen) {
diff --git a/ext/standard/tests/strings/bug78612.phpt b/ext/standard/tests/strings/bug78612.phpt
new file mode 100644 (file)
index 0000000..7dad605
--- /dev/null
@@ -0,0 +1,18 @@
+--TEST--
+Bug #78612 (strtr leaks memory when integer keys are used and the subject string shorter).
+--FILE--
+<?php
+
+$find_replace = array();
+$_a = 7111222333000001;
+$_b = 5000001;
+
+for ($j=0; $j<10; $j++) {
+       $find_replace[$_a + $j] = $_b + $j;
+}
+
+echo strtr('Hello', $find_replace), "\n";
+
+?>
+--EXPECT--
+Hello