diff options
| author | nsfisis <nsfisis@gmail.com> | 2024-01-27 13:22:56 +0900 |
|---|---|---|
| committer | nsfisis <nsfisis@gmail.com> | 2024-02-26 11:07:06 +0900 |
| commit | 900377463a8264871ee42e488112b076b7973b6a (patch) | |
| tree | bf727d3484ca7c8d35f18ef29ea8d9305d4b57da /src/BinaryFormat/Decoder.php | |
| parent | e2495878b872b341e6e04eed31dd255b1a6e256f (diff) | |
| download | php-waddiwasi-900377463a8264871ee42e488112b076b7973b6a.tar.gz php-waddiwasi-900377463a8264871ee42e488112b076b7973b6a.tar.zst php-waddiwasi-900377463a8264871ee42e488112b076b7973b6a.zip | |
feat: partially implement execution
Diffstat (limited to 'src/BinaryFormat/Decoder.php')
| -rw-r--r-- | src/BinaryFormat/Decoder.php | 15 |
1 files changed, 9 insertions, 6 deletions
diff --git a/src/BinaryFormat/Decoder.php b/src/BinaryFormat/Decoder.php index f95c26e..be1b44d 100644 --- a/src/BinaryFormat/Decoder.php +++ b/src/BinaryFormat/Decoder.php @@ -132,12 +132,12 @@ final class Decoder { assert($this->pos === 4); $this->ensureNBytesRemains(4); - $b1 = ord($this->input[0]); - $b2 = ord($this->input[1]); - $b3 = ord($this->input[2]); - $b4 = ord($this->input[3]); + $b1 = ord($this->input[4]); + $b2 = ord($this->input[5]); + $b3 = ord($this->input[6]); + $b4 = ord($this->input[7]); if ([$b1, $b2, $b3, $b4] !== [0x01, 0x00, 0x00, 0x00]) { - throw new InvalidBinaryFormatException("version"); + throw new InvalidBinaryFormatException(sprintf("version: [%x, %x, %x, %x]", $b1, $b2, $b3, $b4)); } $this->pos += 4; } @@ -150,6 +150,9 @@ final class Decoder private function decodeSection(SectionId $sectionId, callable $decoder): mixed { $this->skipCustomSections(); + if ($this->eof()) { + return null; + } $idValue = $this->peekByte(); $id = SectionId::tryFrom($idValue); @@ -983,7 +986,7 @@ final class Decoder private function ensureNBytesRemains(int $n): void { if ($this->inputSize < $this->pos + $n) { - throw new InvalidBinaryFormatException("ensureNBytesRemains"); + throw new InvalidBinaryFormatException("ensureNBytesRemains: $this->inputSize < $this->pos + $n"); } } |
