From 4baf569d81eb55fa35a1ccbe8ae179c864272a4a Mon Sep 17 00:00:00 2001 From: Matthew Brown Date: Mon, 4 Oct 2021 18:15:52 -0400 Subject: [PATCH] Use safer json_decode_with_error function --- lib/protobuf.php | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/lib/protobuf.php b/lib/protobuf.php index 0c67683..4d94eb1 100644 --- a/lib/protobuf.php +++ b/lib/protobuf.php @@ -820,12 +820,13 @@ public static function FromString(string $str): mixed { if ($str === "null") { return null; } - $data = \json_decode($str, true, 512, \JSON_FB_HACK_ARRAYS); + $error_data = null; + $data = \json_decode_with_error($str, inout $error_data, true, 512, \JSON_FB_HACK_ARRAYS); if ($data !== null) { return $data; } throw new \ProtobufException( - "json_decode failed; ".\json_last_error_msg(), + "json_decode failed; ".($error_data[1] ?? ''), ); }