From 4292628c80ef0ac5cafc19f48c997502cf6c14bf Mon Sep 17 00:00:00 2001 From: Niklas Fasching Date: Tue, 29 Oct 2019 01:03:10 +0100 Subject: [PATCH] Fix ExplicitLineBreak parsing fuzzed index out of range and moved range check into for condition as \\ followed by spaces at the end of the inline text should not be turned into an ExplicitLineBreak (just like \\ not followed by spaces). --- org/inline.go | 4 ++-- org/testdata/misc.html | 12 ++++++++++-- org/testdata/misc.org | 3 +++ org/testdata/misc.pretty_org | 3 +++ 4 files changed, 18 insertions(+), 4 deletions(-) diff --git a/org/inline.go b/org/inline.go index 02d5a15..09c58f1 100644 --- a/org/inline.go +++ b/org/inline.go @@ -147,8 +147,8 @@ func (d *Document) parseExplicitLineBreakOrLatexFragment(input string, start int switch { case start+2 >= len(input): case input[start+1] == '\\' && start != 0 && input[start-1] != '\n': - for i := start + 2; unicode.IsSpace(rune(input[i])); i++ { - if i >= len(input) || input[i] == '\n' { + for i := start + 2; i <= len(input)-1 && unicode.IsSpace(rune(input[i])); i++ { + if input[i] == '\n' { return i + 1 - start, ExplicitLineBreak{} } } diff --git a/org/testdata/misc.html b/org/testdata/misc.html index f8b2397..c209ccd 100644 --- a/org/testdata/misc.html +++ b/org/testdata/misc.html @@ -68,9 +68,11 @@ +
  • index out of range in explicit line break parsing +
  • -
  • Footnotes +
  • Footnotes
  • @@ -499,7 +501,13 @@ index out of range in headline priority parsing

    [#B

    -

    +

    +index out of range in explicit line break parsing +

    +

    +0\\ +

    +

    Footnotes

    diff --git a/org/testdata/misc.org b/org/testdata/misc.org index e8813a7..78d5dbc 100644 --- a/org/testdata/misc.org +++ b/org/testdata/misc.org @@ -136,6 +136,9 @@ When inserting an image link like [[/home/amos/Pictures/Screenshots/img-2017-09- ** misc fuzz / regression / edge case *** index out of range in headline priority parsing **** [#B +*** index out of range in explicit line break parsing +0\\ + * Footnotes [fn:1] a footnote /with/ *markup* diff --git a/org/testdata/misc.pretty_org b/org/testdata/misc.pretty_org index cc128a3..ff61450 100644 --- a/org/testdata/misc.pretty_org +++ b/org/testdata/misc.pretty_org @@ -136,6 +136,9 @@ When inserting an image link like [[/home/amos/Pictures/Screenshots/img-2017-09- ** misc fuzz / regression / edge case *** index out of range in headline priority parsing **** [#B +*** index out of range in explicit line break parsing +0\\ + * Footnotes [fn:1] a footnote /with/ *markup*