From 7794bae40d9a4a257a8c0cadce53f0d136eec9bd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=8C=83=E5=86=A0=E7=99=BB?= Date: Fri, 22 Nov 2024 19:19:46 +0800 Subject: [PATCH 1/6] Fix: Ensure unpacked data is an array before using array_key_exists() --- src/Client.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Client.php b/src/Client.php index 92c0afb..581693f 100644 --- a/src/Client.php +++ b/src/Client.php @@ -70,7 +70,7 @@ public function __call($name, $arguments) throw new RecvFailedException('Recv failed'); } - return with($packer->unpack($ret), function ($data) { + return with((array) $packer->unpack($ret), function ($data) { if (array_key_exists('result', $data)) { return $data['result']; } From b56d58b3465262d114109c6d8bf6d43dc273cf51 Mon Sep 17 00:00:00 2001 From: Deeka Wong <8337659+huangdijia@users.noreply.github.com> Date: Thu, 9 Oct 2025 10:27:12 +0800 Subject: [PATCH 2/6] Add validation for unpacked data in Client Throws a RecvFailedException if the unpacked data is not an array, improving error handling for invalid responses. --- src/Client.php | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/Client.php b/src/Client.php index 581693f..cb36cea 100644 --- a/src/Client.php +++ b/src/Client.php @@ -70,7 +70,11 @@ public function __call($name, $arguments) throw new RecvFailedException('Recv failed'); } - return with((array) $packer->unpack($ret), function ($data) { + return with((array) $packer->unpack($ret), function ($data) use ($ret) { + if (! is_array($data)) { + throw new RecvFailedException('Recv failed, invalid data: ' . $ret); + } + if (array_key_exists('result', $data)) { return $data['result']; } From 1d625fd07accfe120e492602f4301cbd4088d107 Mon Sep 17 00:00:00 2001 From: Deeka Wong <8337659+huangdijia@users.noreply.github.com> Date: Thu, 9 Oct 2025 10:27:47 +0800 Subject: [PATCH 3/6] Fix: Ensure unpacked data is treated as an array in Client --- src/Client.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Client.php b/src/Client.php index cb36cea..204c1ec 100644 --- a/src/Client.php +++ b/src/Client.php @@ -70,7 +70,7 @@ public function __call($name, $arguments) throw new RecvFailedException('Recv failed'); } - return with((array) $packer->unpack($ret), function ($data) use ($ret) { + return with($packer->unpack($ret), function ($data) use ($ret) { if (! is_array($data)) { throw new RecvFailedException('Recv failed, invalid data: ' . $ret); } From a4326ecaeeee142dadcb20f6601e302f9752bada Mon Sep 17 00:00:00 2001 From: Deeka Wong <8337659+huangdijia@users.noreply.github.com> Date: Thu, 9 Oct 2025 10:28:35 +0800 Subject: [PATCH 4/6] chore: Add allow-plugins configuration for composer-normalize --- composer.json | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/composer.json b/composer.json index fdd491a..b4789ed 100644 --- a/composer.json +++ b/composer.json @@ -35,7 +35,10 @@ } }, "config": { - "sort-packages": true + "sort-packages": true, + "allow-plugins": { + "ergebnis/composer-normalize": true + } }, "extra": { "branch-alias": { From 55ccd3c22367df2fb7b21e24efaab7279e08f823 Mon Sep 17 00:00:00 2001 From: Deeka Wong <8337659+huangdijia@users.noreply.github.com> Date: Thu, 9 Oct 2025 10:31:07 +0800 Subject: [PATCH 5/6] Fix: Ensure unpacked data is treated as an array and improve error handling in Client --- src/Client.php | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/src/Client.php b/src/Client.php index 204c1ec..a406134 100644 --- a/src/Client.php +++ b/src/Client.php @@ -70,16 +70,12 @@ public function __call($name, $arguments) throw new RecvFailedException('Recv failed'); } - return with($packer->unpack($ret), function ($data) use ($ret) { - if (! is_array($data)) { - throw new RecvFailedException('Recv failed, invalid data: ' . $ret); - } - + return with((array) $packer->unpack($ret), function ($data) use ($ret) { if (array_key_exists('result', $data)) { return $data['result']; } - throw new ServerException($data['error'] ?? []); + throw new ServerException($data['error'] ?? ['code' => 0, 'message' => 'Recv failed, invalid data: ' . $ret]); }); }; From 0a50458c40d7afe3323b48e1abc0877c1245c2c2 Mon Sep 17 00:00:00 2001 From: Deeka Wong <8337659+huangdijia@users.noreply.github.com> Date: Thu, 9 Oct 2025 10:31:45 +0800 Subject: [PATCH 6/6] Fix: Improve error message for invalid data in ServerException --- src/Client.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Client.php b/src/Client.php index a406134..1951533 100644 --- a/src/Client.php +++ b/src/Client.php @@ -75,7 +75,7 @@ public function __call($name, $arguments) return $data['result']; } - throw new ServerException($data['error'] ?? ['code' => 0, 'message' => 'Recv failed, invalid data: ' . $ret]); + throw new ServerException($data['error'] ?? ['code' => 0, 'message' => 'Invalid data: ' . $ret]); }); };