8000 bug #40707 [Yaml] Fixed infinite loop when parser goes through an add… · symfony/symfony@ed576b2 · GitHub
[go: up one dir, main page]

Skip to content

Commit ed576b2

Browse files
committed
bug #40707 [Yaml] Fixed infinite loop when parser goes through an additional and invalid closing tag (alexandre-daubois)
This PR was merged into the 4.4 branch. Discussion ---------- [Yaml] Fixed infinite loop when parser goes through an additional and invalid closing tag | Q | A | ------------- | --- | Branch? | 4.4 and above | Bug fix? | yes | New feature? | no <!-- please update src/**/CHANGELOG.md files --> | Deprecations? | no <!-- please update UPGRADE-*.md and src/**/CHANGELOG.md files --> | Tickets | Fix #40706 <!-- prefix each issue number with "Fix #", no need to create an issue if none exist, explain below instead --> | License | MIT | Doc PR | <!-- required for new features --> Instead of letting the parser goes in an infinite loop because it can't get the right closing tag, throw an exception when the additional and invalid closing tag is found Commits ------- d5f8c88 [Yaml] Fixed infinite loop when parser goes through an additional and invalid closing tag
2 parents e2f430d + d5f8c88 commit ed576b2

File tree

2 files changed

+23
-0
lines changed

2 files changed

+23
-0
lines changed

src/Symfony/Component/Yaml/Parser.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1225,6 +1225,10 @@ private function lexUnquotedString(int &$cursor): string
12251225
$offset = $cursor;
12261226
$cursor += strcspn($this->currentLine, '[]{},: ', $cursor);
12271227

1228+
if ($cursor === $offset) {
1229+
throw new ParseException('Malformed unquoted YAML string.');
1230+
}
1231+
12281232
return substr($this->currentLine, $offset, $cursor - $offset);
12291233
}
12301234

src/Symfony/Component/Yaml/Tests/ParserTest.php

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2676,6 +2676,25 @@ public function testParseValueWithNegativeModifiers()
26762676
);
26772677
}
26782678

2679+
public function testThrowExceptionIfInvalidAdditionalClosingTagOccurs()
2680+
{
2681+
$yaml = '{
2682+
"object": {
2683+
"array": [
2684+
"a",
2685+
"b",
2686+
"c"
2687+
]
2688+
],
2689+
}
2690+
}';
2691+
2692+
$this->expectException(ParseException::class);
2693+
$this->expectExceptionMessage('Malformed unquoted YAML string at line 8 (near " ],").');
2694+
2695+
$this->parser->parse($yaml);
2696+
}
2697+
26792698
public function testWhitespaceAtEndOfLine()
26802699
{
26812700
$yaml = "\nfoo:\n arguments: [ '@bar' ] \n";

0 commit comments

Comments
 (0)
0