Skip to content

Commit d777db8

Browse files
committed
Add pathological test for deeply-nested blocks
1 parent 92dbad9 commit d777db8

File tree

2 files changed

+24
-4
lines changed

2 files changed

+24
-4
lines changed

tests/pathological/convert.php

+7-3
Original file line numberDiff line numberDiff line change
@@ -35,12 +35,16 @@
3535
exit(1);
3636
}
3737

38-
$environment = new Environment();
38+
$config = [];
39+
if (isset($argv[1])) {
40+
$config = \json_decode($argv[1], true);
41+
}
42+
43+
$environment = new Environment($config);
3944
$environment->addExtension(new CommonMarkCoreExtension());
4045

4146
// Enable additional extensions if requested
42-
$extension = $argv[1] ?? null;
43-
switch ($argv[1] ?? null) {
47+
switch ($argv[2] ?? null) {
4448
case 'table':
4549
$environment->addExtension(new TableExtension());
4650
break;

tests/pathological/test.php

+17-1
Original file line numberDiff line numberDiff line change
@@ -221,6 +221,22 @@
221221
'input' => static fn($n) => \str_repeat(">", $n) . \str_repeat(".", $n) . "\n",
222222
'expected' => static fn($n) => \str_repeat("<blockquote>\n", $n) . '<p>' . \str_repeat('.', $n) . "</p>\n" . \str_repeat("</blockquote>\n", $n),
223223
],
224+
'CVE-2023-24824 test 1' => [
225+
'ref' => 'https://github.com/github/cmark-gfm/security/advisories/GHSA-66g8-4hjf-77xh',
226+
'sizes' => [1_000, 10_000, 100_000],
227+
'input' => static fn($n) => \str_repeat(">", $n) . \str_repeat("a*", $n) . "\n",
228+
'configuration' => [
229+
'max_nesting_level' => 1_000,
230+
],
231+
],
232+
'CVE-2023-24824 test 2' => [
233+
'ref' => 'https://github.com/github/cmark-gfm/security/advisories/GHSA-66g8-4hjf-77xh',
234+
'sizes' => [500, 5_000, 50_000],
235+
'input' => static fn($n) => \str_repeat(" -", $n) . 'x' . \str_repeat("\n", $n),
236+
'configuration' => [
237+
'max_nesting_level' => 500,
238+
],
239+
],
224240
'CVE-2023-26485 test 1' => [
225241
'ref' => 'https://github.com/github/cmark-gfm/security/advisories/GHSA-r8vr-c48j-fcc5',
226242
'sizes' => [50, 500, 5_000], // ideally should be 1000, 10_000, 100_000 but recursive rendering makes large sizes fail
@@ -294,7 +310,7 @@
294310
if (isset($_ENV['CI']) || isset($_SERVER['CI'])) {
295311
$command = ['php', 'convert.php'];
296312
} else {
297-
$command = ['php', '-n', 'convert.php'];
313+
$command = ['php', '-n', 'convert.php', \json_encode($case['configuration'] ?? [])];
298314
}
299315

300316
if (isset($case['extension'])) {

0 commit comments

Comments
 (0)