[Yaml] Fixed infinite loop when parser goes through an additional and invalid closing tag

Instead of letting the parser goes in an infinite loop, throw an exception when the additional and invalid is found
This commit is contained in:
Alexandre Daubois 2021-04-04 20:39:25 +02:00
parent 3b1948fe72
commit d5f8c887a2
2 changed files with 23 additions and 0 deletions

View File

@ -1225,6 +1225,10 @@ class Parser
$offset = $cursor;
$cursor += strcspn($this->currentLine, '[]{},: ', $cursor);
if ($cursor === $offset) {
throw new ParseException('Malformed unquoted YAML string.');
}
return substr($this->currentLine, $offset, $cursor - $offset);
}

View File

@ -2676,6 +2676,25 @@ YAML;
);
}
public function testThrowExceptionIfInvalidAdditionalClosingTagOccurs()
{
$yaml = '{
"object": {
"array": [
"a",
"b",
"c"
]
],
}
}';
$this->expectException(ParseException::class);
$this->expectExceptionMessage('Malformed unquoted YAML string at line 8 (near " ],").');
$this->parser->parse($yaml);
}
public function testWhitespaceAtEndOfLine()
{
$yaml = "\nfoo:\n arguments: [ '@bar' ] \n";