aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
-rw-r--r--BUGS9
-rw-r--r--phpunit.xml4
-rw-r--r--src/WebAssembly/BinaryFormat/Decoder.php31
3 files changed, 7 insertions, 37 deletions
diff --git a/BUGS b/BUGS
index 3e88d14..ff37515 100644
--- a/BUGS
+++ b/BUGS
@@ -2,14 +2,7 @@
## Validation
+* AlignTest
* ImportsTest
* LinkingTest
-
-## Misc.
-
-* AlignTest
-* CustomTest
* SkipStackGuardPageTest
-* Utf8CustomSectionIdTest
-* Utf8ImportFieldTest
-* Utf8ImportModuleTest
diff --git a/phpunit.xml b/phpunit.xml
index a6c6ac1..2e62c6f 100644
--- a/phpunit.xml
+++ b/phpunit.xml
@@ -29,6 +29,7 @@
<file>tests/src/SpecTestsuites/Core/CallTest.php</file>
<file>tests/src/SpecTestsuites/Core/ConstTest.php</file>
<file>tests/src/SpecTestsuites/Core/ConversionsTest.php</file>
+ <file>tests/src/SpecTestsuites/Core/CustomTest.php</file>
<file>tests/src/SpecTestsuites/Core/DataTest.php</file>
<file>tests/src/SpecTestsuites/Core/ElemTest.php</file>
<file>tests/src/SpecTestsuites/Core/EndiannessTest.php</file>
@@ -97,6 +98,9 @@
<file>tests/src/SpecTestsuites/Core/UnreachedInvalidTest.php</file>
<file>tests/src/SpecTestsuites/Core/UnreachedValidTest.php</file>
<file>tests/src/SpecTestsuites/Core/UnwindTest.php</file>
+ <file>tests/src/SpecTestsuites/Core/Utf8CustomSectionIdTest.php</file>
+ <file>tests/src/SpecTestsuites/Core/Utf8ImportFieldTest.php</file>
+ <file>tests/src/SpecTestsuites/Core/Utf8ImportModuleTest.php</file>
<file>tests/src/SpecTestsuites/Core/Utf8InvalidEncodingTest.php</file>
</testsuite>
</testsuites>
diff --git a/src/WebAssembly/BinaryFormat/Decoder.php b/src/WebAssembly/BinaryFormat/Decoder.php
index f0a5c29..ff23a5d 100644
--- a/src/WebAssembly/BinaryFormat/Decoder.php
+++ b/src/WebAssembly/BinaryFormat/Decoder.php
@@ -1119,35 +1119,8 @@ final class Decoder
*/
private function implodeUtf8BytesToString(array $bytes): ?string
{
- $s = '';
- $count = count($bytes);
- for ($i = 0; $i < $count; $i++) {
- if (($bytes[$i] & 0x80) === 0) {
- $code = $bytes[$i];
- } elseif (($bytes[$i] & 0xE0) === 0xC0) {
- if ($count <= $i + 1) {
- return null;
- }
- $code = (($bytes[$i] & 0x1F) << 6) | ($bytes[$i + 1] & 0x3F);
- $i++;
- } elseif (($bytes[$i] & 0xF0) === 0xE0) {
- if ($count <= $i + 2) {
- return null;
- }
- $code = (($bytes[$i] & 0x0F) << 12) | (($bytes[$i + 1] & 0x3F) << 6) | ($bytes[$i + 2] & 0x3F);
- $i += 2;
- } elseif (($bytes[$i] & 0xF8) === 0xF0) {
- if ($count <= $i + 3) {
- return null;
- }
- $code = (($bytes[$i] & 0x07) << 18) | (($bytes[$i + 1] & 0x3F) << 12) | (($bytes[$i + 2] & 0x3F) << 6) | ($bytes[$i + 3] & 0x3F);
- $i += 3;
- } else {
- return null;
- }
- $s .= mb_chr($code, 'UTF-8');
- }
- return $s;
+ $s = pack('C*', ...$bytes);
+ return mb_check_encoding($s, 'UTF-8') ? $s : null;
}
/**