commonmarker 0.23.6 → 0.23.7
Sign up to get free protection for your applications and to get access to all the features.
Potentially problematic release.
This version of commonmarker might be problematic. Click here for more details.
- checksums.yaml +4 -4
- data/ext/commonmarker/arena.c +8 -7
- data/ext/commonmarker/autolink.c +202 -155
- data/ext/commonmarker/blocks.c +14 -0
- data/ext/commonmarker/cmark-gfm-extension_api.h +1 -0
- data/ext/commonmarker/commonmarker.c +1 -0
- data/ext/commonmarker/inlines.c +130 -58
- data/ext/commonmarker/map.c +11 -4
- data/ext/commonmarker/map.h +5 -2
- data/ext/commonmarker/node.c +34 -0
- data/ext/commonmarker/node.h +26 -6
- data/ext/commonmarker/parser.h +1 -0
- data/ext/commonmarker/references.c +1 -0
- data/ext/commonmarker/scanners.c +13916 -10368
- data/ext/commonmarker/scanners.h +8 -0
- data/ext/commonmarker/strikethrough.c +1 -1
- data/ext/commonmarker/table.c +59 -35
- data/lib/commonmarker/config.rb +15 -13
- data/lib/commonmarker/renderer.rb +1 -1
- data/lib/commonmarker/version.rb +1 -1
- data/lib/commonmarker.rb +27 -25
- metadata +7 -7
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 9bc9c02a66017c3e576e64845a18440060df1f7e0082c192b51e3c7ebfd1413e
|
4
|
+
data.tar.gz: b7623cfa01c89817fef3f4ba850fb992d27876e7c4d2e3d9e73f085c78c3d3da
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 3f11b3d05d2f7b9c43499c5b4aa868b82263cbc95119106697653300e65fd0a6018ad71584adec7d8b95e9c6a27da39f13c6fbf0cdbfd8185519783f1f8b1bbd
|
7
|
+
data.tar.gz: c9b318e34f244e6cadfecf746dfc61be16dc13965c3cd7add4c0d0ed587a3aff0f9da79e2fb0a1a8aa311ccddd47532924cbf1cfd95e371b33c1d5e2ad9ee563
|
data/ext/commonmarker/arena.c
CHANGED
@@ -68,15 +68,16 @@ static void *arena_calloc(size_t nmem, size_t size) {
|
|
68
68
|
const size_t align = sizeof(size_t) - 1;
|
69
69
|
sz = (sz + align) & ~align;
|
70
70
|
|
71
|
+
struct arena_chunk *chunk;
|
71
72
|
if (sz > A->sz) {
|
72
|
-
A->prev = alloc_arena_chunk(sz, A->prev);
|
73
|
-
|
73
|
+
A->prev = chunk = alloc_arena_chunk(sz, A->prev);
|
74
|
+
} else if (sz > A->sz - A->used) {
|
75
|
+
A = chunk = alloc_arena_chunk(A->sz + A->sz / 2, A);
|
76
|
+
} else {
|
77
|
+
chunk = A;
|
74
78
|
}
|
75
|
-
|
76
|
-
|
77
|
-
}
|
78
|
-
void *ptr = (uint8_t *) A->ptr + A->used;
|
79
|
-
A->used += sz;
|
79
|
+
void *ptr = (uint8_t *) chunk->ptr + chunk->used;
|
80
|
+
chunk->used += sz;
|
80
81
|
*((size_t *) ptr) = sz - sizeof(size_t);
|
81
82
|
return (uint8_t *) ptr + sizeof(size_t);
|
82
83
|
}
|
data/ext/commonmarker/autolink.c
CHANGED
@@ -2,6 +2,7 @@
|
|
2
2
|
#include <parser.h>
|
3
3
|
#include <string.h>
|
4
4
|
#include <utf8.h>
|
5
|
+
#include <stddef.h>
|
5
6
|
|
6
7
|
#if defined(_WIN32)
|
7
8
|
#define strncasecmp _strnicmp
|
@@ -35,44 +36,25 @@ static int sd_autolink_issafe(const uint8_t *link, size_t link_len) {
|
|
35
36
|
}
|
36
37
|
|
37
38
|
static size_t autolink_delim(uint8_t *data, size_t link_end) {
|
38
|
-
uint8_t cclose, copen;
|
39
39
|
size_t i;
|
40
|
+
size_t closing = 0;
|
41
|
+
size_t opening = 0;
|
40
42
|
|
41
|
-
for (i = 0; i < link_end; ++i)
|
42
|
-
|
43
|
+
for (i = 0; i < link_end; ++i) {
|
44
|
+
const uint8_t c = data[i];
|
45
|
+
if (c == '<') {
|
43
46
|
link_end = i;
|
44
47
|
break;
|
48
|
+
} else if (c == '(') {
|
49
|
+
opening++;
|
50
|
+
} else if (c == ')') {
|
51
|
+
closing++;
|
45
52
|
}
|
53
|
+
}
|
46
54
|
|
47
55
|
while (link_end > 0) {
|
48
|
-
|
49
|
-
|
50
|
-
switch (cclose) {
|
56
|
+
switch (data[link_end - 1]) {
|
51
57
|
case ')':
|
52
|
-
copen = '(';
|
53
|
-
break;
|
54
|
-
default:
|
55
|
-
copen = 0;
|
56
|
-
}
|
57
|
-
|
58
|
-
if (strchr("?!.,:*_~'\"", data[link_end - 1]) != NULL)
|
59
|
-
link_end--;
|
60
|
-
|
61
|
-
else if (data[link_end - 1] == ';') {
|
62
|
-
size_t new_end = link_end - 2;
|
63
|
-
|
64
|
-
while (new_end > 0 && cmark_isalpha(data[new_end]))
|
65
|
-
new_end--;
|
66
|
-
|
67
|
-
if (new_end < link_end - 2 && data[new_end] == '&')
|
68
|
-
link_end = new_end;
|
69
|
-
else
|
70
|
-
link_end--;
|
71
|
-
} else if (copen != 0) {
|
72
|
-
size_t closing = 0;
|
73
|
-
size_t opening = 0;
|
74
|
-
i = 0;
|
75
|
-
|
76
58
|
/* Allow any number of matching brackets (as recognised in copen/cclose)
|
77
59
|
* at the end of the URL. If there is a greater number of closing
|
78
60
|
* brackets than opening ones, we remove one character from the end of
|
@@ -80,34 +62,52 @@ static size_t autolink_delim(uint8_t *data, size_t link_end) {
|
|
80
62
|
*
|
81
63
|
* Examples (input text => output linked portion):
|
82
64
|
*
|
83
|
-
*
|
84
|
-
*
|
65
|
+
* http://www.pokemon.com/Pikachu_(Electric)
|
66
|
+
* => http://www.pokemon.com/Pikachu_(Electric)
|
85
67
|
*
|
86
|
-
*
|
87
|
-
*
|
68
|
+
* http://www.pokemon.com/Pikachu_((Electric)
|
69
|
+
* => http://www.pokemon.com/Pikachu_((Electric)
|
88
70
|
*
|
89
|
-
*
|
90
|
-
*
|
71
|
+
* http://www.pokemon.com/Pikachu_(Electric))
|
72
|
+
* => http://www.pokemon.com/Pikachu_(Electric)
|
91
73
|
*
|
92
|
-
*
|
93
|
-
*
|
74
|
+
* http://www.pokemon.com/Pikachu_((Electric))
|
75
|
+
* => http://www.pokemon.com/Pikachu_((Electric))
|
94
76
|
*/
|
95
|
-
|
96
|
-
|
97
|
-
if (data[i] == copen)
|
98
|
-
opening++;
|
99
|
-
else if (data[i] == cclose)
|
100
|
-
closing++;
|
101
|
-
|
102
|
-
i++;
|
77
|
+
if (closing <= opening) {
|
78
|
+
return link_end;
|
103
79
|
}
|
80
|
+
closing--;
|
81
|
+
link_end--;
|
82
|
+
break;
|
83
|
+
case '?':
|
84
|
+
case '!':
|
85
|
+
case '.':
|
86
|
+
case ',':
|
87
|
+
case ':':
|
88
|
+
case '*':
|
89
|
+
case '_':
|
90
|
+
case '~':
|
91
|
+
case '\'':
|
92
|
+
case '"':
|
93
|
+
link_end--;
|
94
|
+
break;
|
95
|
+
case ';': {
|
96
|
+
size_t new_end = link_end - 2;
|
104
97
|
|
105
|
-
|
106
|
-
|
98
|
+
while (new_end > 0 && cmark_isalpha(data[new_end]))
|
99
|
+
new_end--;
|
107
100
|
|
108
|
-
link_end
|
109
|
-
|
101
|
+
if (new_end < link_end - 2 && data[new_end] == '&')
|
102
|
+
link_end = new_end;
|
103
|
+
else
|
104
|
+
link_end--;
|
110
105
|
break;
|
106
|
+
}
|
107
|
+
|
108
|
+
default:
|
109
|
+
return link_end;
|
110
|
+
}
|
111
111
|
}
|
112
112
|
|
113
113
|
return link_end;
|
@@ -116,7 +116,20 @@ static size_t autolink_delim(uint8_t *data, size_t link_end) {
|
|
116
116
|
static size_t check_domain(uint8_t *data, size_t size, int allow_short) {
|
117
117
|
size_t i, np = 0, uscore1 = 0, uscore2 = 0;
|
118
118
|
|
119
|
+
/* The purpose of this code is to reject urls that contain an underscore
|
120
|
+
* in one of the last two segments. Examples:
|
121
|
+
*
|
122
|
+
* www.xxx.yyy.zzz autolinked
|
123
|
+
* www.xxx.yyy._zzz not autolinked
|
124
|
+
* www.xxx._yyy.zzz not autolinked
|
125
|
+
* www._xxx.yyy.zzz autolinked
|
126
|
+
*
|
127
|
+
* The reason is that domain names are allowed to include underscores,
|
128
|
+
* but host names are not. See: https://stackoverflow.com/a/2183140
|
129
|
+
*/
|
119
130
|
for (i = 1; i < size - 1; i++) {
|
131
|
+
if (data[i] == '\\' && i < size - 2)
|
132
|
+
i++;
|
120
133
|
if (data[i] == '_')
|
121
134
|
uscore2++;
|
122
135
|
else if (data[i] == '.') {
|
@@ -127,8 +140,17 @@ static size_t check_domain(uint8_t *data, size_t size, int allow_short) {
|
|
127
140
|
break;
|
128
141
|
}
|
129
142
|
|
130
|
-
if (uscore1 > 0 || uscore2 > 0)
|
131
|
-
|
143
|
+
if (uscore1 > 0 || uscore2 > 0) {
|
144
|
+
/* If the url is very long then accept it despite the underscores,
|
145
|
+
* to avoid quadratic behavior causing a denial of service. See:
|
146
|
+
* https://github.com/github/cmark-gfm/security/advisories/GHSA-29g3-96g3-jg6c
|
147
|
+
* Reasonable urls are unlikely to have more than 10 segments, so
|
148
|
+
* this extra condition shouldn't have any impact on normal usage.
|
149
|
+
*/
|
150
|
+
if (np <= 10) {
|
151
|
+
return 0;
|
152
|
+
}
|
153
|
+
}
|
132
154
|
|
133
155
|
if (allow_short) {
|
134
156
|
/* We don't need a valid domain in the strict sense (with
|
@@ -165,7 +187,7 @@ static cmark_node *www_match(cmark_parser *parser, cmark_node *parent,
|
|
165
187
|
if (link_end == 0)
|
166
188
|
return NULL;
|
167
189
|
|
168
|
-
while (link_end < size && !cmark_isspace(data[link_end]))
|
190
|
+
while (link_end < size && !cmark_isspace(data[link_end]) && data[link_end] != '<')
|
169
191
|
link_end++;
|
170
192
|
|
171
193
|
link_end = autolink_delim(data, link_end);
|
@@ -225,7 +247,7 @@ static cmark_node *url_match(cmark_parser *parser, cmark_node *parent,
|
|
225
247
|
return 0;
|
226
248
|
|
227
249
|
link_end += domain_len;
|
228
|
-
while (link_end < size && !cmark_isspace(data[link_end]))
|
250
|
+
while (link_end < size && !cmark_isspace(data[link_end]) && data[link_end] != '<')
|
229
251
|
link_end++;
|
230
252
|
|
231
253
|
link_end = autolink_delim(data, link_end);
|
@@ -269,142 +291,167 @@ static cmark_node *match(cmark_syntax_extension *ext, cmark_parser *parser,
|
|
269
291
|
// inline was finished in inlines.c.
|
270
292
|
}
|
271
293
|
|
272
|
-
static bool validate_protocol(char protocol[], uint8_t *data,
|
294
|
+
static bool validate_protocol(char protocol[], uint8_t *data, size_t rewind, size_t max_rewind) {
|
273
295
|
size_t len = strlen(protocol);
|
274
296
|
|
297
|
+
if (len > (max_rewind - rewind)) {
|
298
|
+
return false;
|
299
|
+
}
|
300
|
+
|
275
301
|
// Check that the protocol matches
|
276
|
-
|
277
|
-
|
278
|
-
|
279
|
-
|
302
|
+
if (memcmp(data - rewind - len, protocol, len) != 0) {
|
303
|
+
return false;
|
304
|
+
}
|
305
|
+
|
306
|
+
if (len == (max_rewind - rewind)) {
|
307
|
+
return true;
|
280
308
|
}
|
281
309
|
|
282
|
-
char prev_char = data[-rewind - len - 1];
|
310
|
+
char prev_char = data[-((ptrdiff_t)rewind) - len - 1];
|
283
311
|
|
284
312
|
// Make sure the character before the protocol is non-alphanumeric
|
285
313
|
return !cmark_isalnum(prev_char);
|
286
314
|
}
|
287
315
|
|
288
|
-
static void postprocess_text(cmark_parser *parser, cmark_node *text
|
289
|
-
|
290
|
-
|
291
|
-
|
316
|
+
static void postprocess_text(cmark_parser *parser, cmark_node *text) {
|
317
|
+
size_t start = 0;
|
318
|
+
size_t offset = 0;
|
319
|
+
// `text` is going to be split into a list of nodes containing shorter segments
|
320
|
+
// of text, so we detach the memory buffer from text and use `cmark_chunk_dup` to
|
321
|
+
// create references to it. Later, `cmark_chunk_to_cstr` is used to convert
|
322
|
+
// the references into allocated buffers. The detached buffer is freed before we
|
323
|
+
// return.
|
324
|
+
cmark_chunk detached_chunk = text->as.literal;
|
325
|
+
text->as.literal = cmark_chunk_dup(&detached_chunk, 0, detached_chunk.len);
|
326
|
+
|
327
|
+
uint8_t *data = text->as.literal.data;
|
328
|
+
size_t remaining = text->as.literal.len;
|
329
|
+
|
330
|
+
while (true) {
|
331
|
+
size_t link_end;
|
332
|
+
uint8_t *at;
|
333
|
+
bool auto_mailto = true;
|
334
|
+
bool is_xmpp = false;
|
335
|
+
size_t rewind;
|
336
|
+
size_t max_rewind;
|
337
|
+
size_t np = 0;
|
338
|
+
|
339
|
+
if (offset >= remaining)
|
340
|
+
break;
|
292
341
|
|
293
|
-
|
294
|
-
|
295
|
-
|
296
|
-
size_t size = text->as.literal.len;
|
297
|
-
bool auto_mailto = true;
|
298
|
-
bool is_xmpp = false;
|
299
|
-
int rewind, max_rewind,
|
300
|
-
nb = 0, np = 0, ns = 0;
|
342
|
+
at = (uint8_t *)memchr(data + start + offset, '@', remaining - offset);
|
343
|
+
if (!at)
|
344
|
+
break;
|
301
345
|
|
302
|
-
|
303
|
-
return;
|
346
|
+
max_rewind = at - (data + start + offset);
|
304
347
|
|
305
|
-
|
306
|
-
|
348
|
+
found_at:
|
349
|
+
for (rewind = 0; rewind < max_rewind; ++rewind) {
|
350
|
+
uint8_t c = data[start + offset + max_rewind - rewind - 1];
|
307
351
|
|
308
|
-
|
309
|
-
|
310
|
-
return;
|
352
|
+
if (cmark_isalnum(c))
|
353
|
+
continue;
|
311
354
|
|
312
|
-
|
313
|
-
|
314
|
-
size -= max_rewind;
|
355
|
+
if (strchr(".+-_", c) != NULL)
|
356
|
+
continue;
|
315
357
|
|
316
|
-
|
317
|
-
|
358
|
+
if (strchr(":", c) != NULL) {
|
359
|
+
if (validate_protocol("mailto:", data + start + offset + max_rewind, rewind, max_rewind)) {
|
360
|
+
auto_mailto = false;
|
361
|
+
continue;
|
362
|
+
}
|
363
|
+
|
364
|
+
if (validate_protocol("xmpp:", data + start + offset + max_rewind, rewind, max_rewind)) {
|
365
|
+
auto_mailto = false;
|
366
|
+
is_xmpp = true;
|
367
|
+
continue;
|
368
|
+
}
|
369
|
+
}
|
318
370
|
|
319
|
-
|
320
|
-
|
371
|
+
break;
|
372
|
+
}
|
321
373
|
|
322
|
-
if (
|
374
|
+
if (rewind == 0) {
|
375
|
+
offset += max_rewind + 1;
|
323
376
|
continue;
|
377
|
+
}
|
324
378
|
|
325
|
-
|
326
|
-
|
327
|
-
|
379
|
+
assert(data[start + offset + max_rewind] == '@');
|
380
|
+
for (link_end = 1; link_end < remaining - offset - max_rewind; ++link_end) {
|
381
|
+
uint8_t c = data[start + offset + max_rewind + link_end];
|
382
|
+
|
383
|
+
if (cmark_isalnum(c))
|
328
384
|
continue;
|
329
|
-
}
|
330
385
|
|
331
|
-
if (
|
332
|
-
|
333
|
-
|
386
|
+
if (c == '@') {
|
387
|
+
// Found another '@', so go back and try again with an updated offset and max_rewind.
|
388
|
+
offset += max_rewind + 1;
|
389
|
+
max_rewind = link_end - 1;
|
390
|
+
goto found_at;
|
391
|
+
} else if (c == '.' && link_end < remaining - offset - max_rewind - 1 &&
|
392
|
+
cmark_isalnum(data[start + offset + max_rewind + link_end + 1]))
|
393
|
+
np++;
|
394
|
+
else if (c == '/' && is_xmpp)
|
334
395
|
continue;
|
335
|
-
|
396
|
+
else if (c != '-' && c != '_')
|
397
|
+
break;
|
336
398
|
}
|
337
399
|
|
338
|
-
|
339
|
-
|
340
|
-
|
341
|
-
|
342
|
-
postprocess_text(parser, text, max_rewind + 1 + offset, depth + 1);
|
343
|
-
return;
|
344
|
-
}
|
345
|
-
|
346
|
-
for (link_end = 0; link_end < size; ++link_end) {
|
347
|
-
uint8_t c = data[link_end];
|
348
|
-
|
349
|
-
if (cmark_isalnum(c))
|
350
|
-
continue;
|
351
|
-
|
352
|
-
if (c == '@')
|
353
|
-
nb++;
|
354
|
-
else if (c == '.' && link_end < size - 1 && cmark_isalnum(data[link_end + 1]))
|
355
|
-
np++;
|
356
|
-
else if (c == '/' && is_xmpp)
|
400
|
+
if (link_end < 2 || np == 0 ||
|
401
|
+
(!cmark_isalpha(data[start + offset + max_rewind + link_end - 1]) &&
|
402
|
+
data[start + offset + max_rewind + link_end - 1] != '.')) {
|
403
|
+
offset += max_rewind + link_end;
|
357
404
|
continue;
|
358
|
-
|
359
|
-
break;
|
360
|
-
}
|
405
|
+
}
|
361
406
|
|
362
|
-
|
363
|
-
(!cmark_isalpha(data[link_end - 1]) && data[link_end - 1] != '.')) {
|
364
|
-
postprocess_text(parser, text, max_rewind + 1 + offset, depth + 1);
|
365
|
-
return;
|
366
|
-
}
|
407
|
+
link_end = autolink_delim(data + start + offset + max_rewind, link_end);
|
367
408
|
|
368
|
-
|
409
|
+
if (link_end == 0) {
|
410
|
+
offset += max_rewind + 1;
|
411
|
+
continue;
|
412
|
+
}
|
369
413
|
|
370
|
-
|
371
|
-
|
372
|
-
|
373
|
-
|
414
|
+
cmark_node *link_node = cmark_node_new_with_mem(CMARK_NODE_LINK, parser->mem);
|
415
|
+
cmark_strbuf buf;
|
416
|
+
cmark_strbuf_init(parser->mem, &buf, 10);
|
417
|
+
if (auto_mailto)
|
418
|
+
cmark_strbuf_puts(&buf, "mailto:");
|
419
|
+
cmark_strbuf_put(&buf, data + start + offset + max_rewind - rewind, (bufsize_t)(link_end + rewind));
|
420
|
+
link_node->as.link.url = cmark_chunk_buf_detach(&buf);
|
421
|
+
|
422
|
+
cmark_node *link_text = cmark_node_new_with_mem(CMARK_NODE_TEXT, parser->mem);
|
423
|
+
cmark_chunk email = cmark_chunk_dup(
|
424
|
+
&detached_chunk,
|
425
|
+
(bufsize_t)(start + offset + max_rewind - rewind),
|
426
|
+
(bufsize_t)(link_end + rewind));
|
427
|
+
cmark_chunk_to_cstr(parser->mem, &email);
|
428
|
+
link_text->as.literal = email;
|
429
|
+
cmark_node_append_child(link_node, link_text);
|
374
430
|
|
375
|
-
|
431
|
+
cmark_node_insert_after(text, link_node);
|
376
432
|
|
377
|
-
|
378
|
-
|
379
|
-
|
380
|
-
|
381
|
-
cmark_strbuf_puts(&buf, "mailto:");
|
382
|
-
cmark_strbuf_put(&buf, data - rewind, (bufsize_t)(link_end + rewind));
|
383
|
-
link_node->as.link.url = cmark_chunk_buf_detach(&buf);
|
384
|
-
|
385
|
-
cmark_node *link_text = cmark_node_new_with_mem(CMARK_NODE_TEXT, parser->mem);
|
386
|
-
cmark_chunk email = cmark_chunk_dup(
|
387
|
-
&text->as.literal,
|
388
|
-
offset + max_rewind - rewind,
|
389
|
-
(bufsize_t)(link_end + rewind));
|
390
|
-
cmark_chunk_to_cstr(parser->mem, &email);
|
391
|
-
link_text->as.literal = email;
|
392
|
-
cmark_node_append_child(link_node, link_text);
|
433
|
+
cmark_node *post = cmark_node_new_with_mem(CMARK_NODE_TEXT, parser->mem);
|
434
|
+
post->as.literal = cmark_chunk_dup(&detached_chunk,
|
435
|
+
(bufsize_t)(start + offset + max_rewind + link_end),
|
436
|
+
(bufsize_t)(remaining - offset - max_rewind - link_end));
|
393
437
|
|
394
|
-
|
438
|
+
cmark_node_insert_after(link_node, post);
|
395
439
|
|
396
|
-
|
397
|
-
|
398
|
-
(bufsize_t)(offset + max_rewind + link_end),
|
399
|
-
(bufsize_t)(size - link_end));
|
400
|
-
cmark_chunk_to_cstr(parser->mem, &post->as.literal);
|
440
|
+
text->as.literal = cmark_chunk_dup(&detached_chunk, (bufsize_t)start, (bufsize_t)(offset + max_rewind - rewind));
|
441
|
+
cmark_chunk_to_cstr(parser->mem, &text->as.literal);
|
401
442
|
|
402
|
-
|
443
|
+
text = post;
|
444
|
+
start += offset + max_rewind + link_end;
|
445
|
+
remaining -= offset + max_rewind + link_end;
|
446
|
+
offset = 0;
|
447
|
+
}
|
403
448
|
|
404
|
-
|
405
|
-
text->as.literal.
|
449
|
+
// Convert the reference to allocated memory.
|
450
|
+
assert(!text->as.literal.alloc);
|
451
|
+
cmark_chunk_to_cstr(parser->mem, &text->as.literal);
|
406
452
|
|
407
|
-
|
453
|
+
// Free the detached buffer.
|
454
|
+
cmark_chunk_free(parser->mem, &detached_chunk);
|
408
455
|
}
|
409
456
|
|
410
457
|
static cmark_node *postprocess(cmark_syntax_extension *ext, cmark_parser *parser, cmark_node *root) {
|
@@ -431,7 +478,7 @@ static cmark_node *postprocess(cmark_syntax_extension *ext, cmark_parser *parser
|
|
431
478
|
}
|
432
479
|
|
433
480
|
if (ev == CMARK_EVENT_ENTER && node->type == CMARK_NODE_TEXT) {
|
434
|
-
postprocess_text(parser, node
|
481
|
+
postprocess_text(parser, node);
|
435
482
|
}
|
436
483
|
}
|
437
484
|
|
data/ext/commonmarker/blocks.c
CHANGED
@@ -8,6 +8,7 @@
|
|
8
8
|
#include <stdlib.h>
|
9
9
|
#include <assert.h>
|
10
10
|
#include <stdio.h>
|
11
|
+
#include <limits.h>
|
11
12
|
|
12
13
|
#include "cmark_ctype.h"
|
13
14
|
#include "syntax_extension.h"
|
@@ -639,6 +640,14 @@ static cmark_node *finalize_document(cmark_parser *parser) {
|
|
639
640
|
}
|
640
641
|
|
641
642
|
finalize(parser, parser->root);
|
643
|
+
|
644
|
+
// Limit total size of extra content created from reference links to
|
645
|
+
// document size to avoid superlinear growth. Always allow 100KB.
|
646
|
+
if (parser->total_size > 100000)
|
647
|
+
parser->refmap->max_ref_size = parser->total_size;
|
648
|
+
else
|
649
|
+
parser->refmap->max_ref_size = 100000;
|
650
|
+
|
642
651
|
process_inlines(parser, parser->refmap, parser->options);
|
643
652
|
if (parser->options & CMARK_OPT_FOOTNOTES)
|
644
653
|
process_footnotes(parser);
|
@@ -698,6 +707,11 @@ static void S_parser_feed(cmark_parser *parser, const unsigned char *buffer,
|
|
698
707
|
const unsigned char *end = buffer + len;
|
699
708
|
static const uint8_t repl[] = {239, 191, 189};
|
700
709
|
|
710
|
+
if (len > UINT_MAX - parser->total_size)
|
711
|
+
parser->total_size = UINT_MAX;
|
712
|
+
else
|
713
|
+
parser->total_size += len;
|
714
|
+
|
701
715
|
if (parser->last_buffer_ended_with_cr && *buffer == '\n') {
|
702
716
|
// skip NL if last buffer ended with CR ; see #117
|
703
717
|
buffer++;
|