From 38ea87ad8d69c3f20409c853476f0445de0036ae Mon Sep 17 00:00:00 2001 From: trobro Date: Wed, 9 Apr 2025 17:40:14 +0200 Subject: [PATCH] fix infinite loop for empty ml-string --- src/HJSON/HJSONParser.php | 3 +-- tests/assets/failStr9a_test.hjson | 4 ++++ tests/assets/strings3_result.hjson | 1 + tests/assets/strings3_result.json | 1 + tests/assets/strings3_test.hjson | 1 + 5 files changed, 8 insertions(+), 2 deletions(-) create mode 100644 tests/assets/failStr9a_test.hjson create mode 100644 tests/assets/strings3_result.hjson create mode 100644 tests/assets/strings3_result.json create mode 100644 tests/assets/strings3_test.hjson diff --git a/src/HJSON/HJSONParser.php b/src/HJSON/HJSONParser.php index 1ba5e06..b6c110d 100644 --- a/src/HJSON/HJSONParser.php +++ b/src/HJSON/HJSONParser.php @@ -368,9 +368,8 @@ private function peek($offs) { $index = $this->at + $offs; - // Mimic old behavior with mb_substr if ($index < 0) { - $index = 0; + return null; } if ($index >= $this->textLengthChars) { return ""; diff --git a/tests/assets/failStr9a_test.hjson b/tests/assets/failStr9a_test.hjson new file mode 100644 index 0000000..229b94d --- /dev/null +++ b/tests/assets/failStr9a_test.hjson @@ -0,0 +1,4 @@ +[ +[ += +[['''''' diff --git a/tests/assets/strings3_result.hjson b/tests/assets/strings3_result.hjson new file mode 100644 index 0000000..e16c76d --- /dev/null +++ b/tests/assets/strings3_result.hjson @@ -0,0 +1 @@ +"" diff --git a/tests/assets/strings3_result.json b/tests/assets/strings3_result.json new file mode 100644 index 0000000..e16c76d --- /dev/null +++ b/tests/assets/strings3_result.json @@ -0,0 +1 @@ +"" diff --git a/tests/assets/strings3_test.hjson b/tests/assets/strings3_test.hjson new file mode 100644 index 0000000..9cad736 --- /dev/null +++ b/tests/assets/strings3_test.hjson @@ -0,0 +1 @@ +''''''