Skip to content

Commit d28de22

Browse files
committed
fix index out of range panic in reference link
Add checking before accessing the input data. Fix russross#172 and russross#173 issues. Signed-off-by: Tw <[email protected]>
1 parent 54d3f20 commit d28de22

File tree

1 file changed

+4
-1
lines changed

1 file changed

+4
-1
lines changed

markdown.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -541,7 +541,7 @@ func isReference(p *parser, data []byte, tabSize int) int {
541541
}
542542
i++
543543
if p.flags&EXTENSION_FOOTNOTES != 0 {
544-
if data[i] == '^' {
544+
if i < len(data) && data[i] == '^' {
545545
// we can set it to anything here because the proper noteIds will
546546
// be assigned later during the second pass. It just has to be != 0
547547
noteId = 1
@@ -631,6 +631,9 @@ func scanLinkRef(p *parser, data []byte, i int) (linkOffset, linkEnd, titleOffse
631631
for i < len(data) && data[i] != ' ' && data[i] != '\t' && data[i] != '\n' && data[i] != '\r' {
632632
i++
633633
}
634+
if i == len(data) {
635+
return
636+
}
634637
linkEnd = i
635638
if data[linkOffset] == '<' && data[linkEnd-1] == '>' {
636639
linkOffset++

0 commit comments

Comments
 (0)