Skip to content

Commit 9f02cba

Browse files
Add a flag to avoid quadratic loop in try_opening_table_header
1 parent 9d57d8a commit 9f02cba

File tree

2 files changed

+6
-0
lines changed

2 files changed

+6
-0
lines changed

extensions/table.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -240,6 +240,10 @@ static cmark_node *try_opening_table_header(cmark_syntax_extension *self,
240240
const char *parent_string;
241241
uint16_t i;
242242

243+
if (parent_container->flags & CMARK_NODE__TABLE_VISITED) {
244+
return parent_container;
245+
}
246+
243247
if (!scan_table_start(input, len, cmark_parser_get_first_nonspace(parser))) {
244248
return parent_container;
245249
}
@@ -267,6 +271,7 @@ static cmark_node *try_opening_table_header(cmark_syntax_extension *self,
267271
free_table_row(parser->mem, marker_row);
268272
free_table_row(parser->mem, header_row);
269273
cmark_arena_pop();
274+
parent_container->flags |= CMARK_NODE__TABLE_VISITED;
270275
return parent_container;
271276
}
272277

src/node.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ enum cmark_node__internal_flags {
5252
CMARK_NODE__OPEN = (1 << 0),
5353
CMARK_NODE__LAST_LINE_BLANK = (1 << 1),
5454
CMARK_NODE__LAST_LINE_CHECKED = (1 << 2),
55+
CMARK_NODE__TABLE_VISITED = (1 << 3),
5556
};
5657

5758
struct cmark_node {

0 commit comments

Comments
 (0)