Skip to content

Commit

Permalink
Fix entity parser (and api test) to respect length limit on numeric e…
Browse files Browse the repository at this point in the history
…ntities.
  • Loading branch information
jgm committed Nov 11, 2019
1 parent 7d04065 commit cb1cd88
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 4 deletions.
6 changes: 3 additions & 3 deletions api_test/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -837,11 +837,11 @@ static void numeric_entities(test_batch_runner *runner) {
"Valid numeric entity 0x10FFFF");
test_md_to_html(runner, "&#x110000;", "<p>" UTF8_REPL "</p>\n",
"Invalid numeric entity 0x110000");
test_md_to_html(runner, "&#x80000000;", "<p>" UTF8_REPL "</p>\n",
test_md_to_html(runner, "&#x80000000;", "<p>&amp;#x80000000;</p>\n",
"Invalid numeric entity 0x80000000");
test_md_to_html(runner, "&#xFFFFFFFF;", "<p>" UTF8_REPL "</p>\n",
test_md_to_html(runner, "&#xFFFFFFFF;", "<p>&amp;#xFFFFFFFF;</p>\n",
"Invalid numeric entity 0xFFFFFFFF");
test_md_to_html(runner, "&#99999999;", "<p>" UTF8_REPL "</p>\n",
test_md_to_html(runner, "&#99999999;", "<p>&amp;#99999999;</p>\n",
"Invalid numeric entity 99999999");

test_md_to_html(runner, "&#;", "<p>&amp;#;</p>\n",
Expand Down
7 changes: 6 additions & 1 deletion src/inlines.c
Original file line number Diff line number Diff line change
Expand Up @@ -784,13 +784,18 @@ static cmark_node *handle_backslash(subject *subj) {
static cmark_node *handle_entity(subject *subj) {
cmark_strbuf ent = CMARK_BUF_INIT(subj->mem);
bufsize_t len;
int length_limit = 256;

advance(subj);

len = houdini_unescape_ent(&ent, subj->input.data + subj->pos,
subj->input.len - subj->pos);

if (len == 0)
if (peek_char(subj) == '#') {
length_limit = 9; // includes #, optional x for hex, and ;
}

if (len <= 0 || len > length_limit)
return make_str(subj, subj->pos - 1, subj->pos - 1, cmark_chunk_literal("&"));

subj->pos += len;
Expand Down

0 comments on commit cb1cd88

Please sign in to comment.