Skip to content

Commit

Permalink
Reworked duplicate dictionary key detection
Browse files Browse the repository at this point in the history
  • Loading branch information
JoshyPHP committed Nov 26, 2023
1 parent d75b8f5 commit 3d2a936
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions src/Decoder.php
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ protected function decodeAnything(): ArrayObject|array|int|string
protected function decodeDictionary(): ArrayObject
{
$values = [];
$lastKey = null;
$lastKey = '';

++$this->offset;
while ($this->offset <= $this->max)
Expand All @@ -163,10 +163,11 @@ protected function decodeDictionary(): ArrayObject
'5' => $this->decodeFastString('5:files', 7, 'files' ),
default => $this->decodeString()
};
if (isset($lastKey) && strcmp($lastKey, $key) >= 0)
if (strcmp($lastKey, $key) >= 0 && !empty($values))
{
$this->dictionaryComplianceError($key, $lastKey);
}

if ($this->offset <= $this->max)
{
$values[$key] = $this->decodeAnything();
Expand Down

0 comments on commit 3d2a936

Please sign in to comment.