From f69b043136339bbe41a8ba8bb2ff8cd6c0dcb5dd Mon Sep 17 00:00:00 2001 From: Niklas Fasching Date: Sun, 27 Oct 2019 15:24:24 +0100 Subject: [PATCH] Fix index out of range in headline priority parsing fuzzed - counting is hard... --- org/headline.go | 2 +- org/testdata/misc.html | 23 +++++++++++++++++++++-- org/testdata/misc.org | 3 +++ org/testdata/misc.pretty_org | 3 +++ 4 files changed, 28 insertions(+), 3 deletions(-) diff --git a/org/headline.go b/org/headline.go index 4788f34..23b986f 100644 --- a/org/headline.go +++ b/org/headline.go @@ -56,7 +56,7 @@ func (d *Document) parseHeadline(i int, parentStop stopFn) (int, Node) { } } - if len(text) >= 3 && text[0:2] == "[#" && strings.Contains("ABC", text[2:3]) && text[3] == ']' { + if len(text) >= 4 && text[0:2] == "[#" && strings.Contains("ABC", text[2:3]) && text[3] == ']' { headline.Priority = text[2:3] text = strings.TrimSpace(text[4:]) } diff --git a/org/testdata/misc.html b/org/testdata/misc.html index bc3fd0a..f8b2397 100644 --- a/org/testdata/misc.html +++ b/org/testdata/misc.html @@ -60,7 +60,17 @@ -
  • Footnotes +
  • misc fuzz / regression / edge case + +
  • +
  • Footnotes
  • @@ -480,7 +490,16 @@ When inserting an image link like +

    +misc fuzz / regression / edge case +

    +

    +index out of range in headline priority parsing +

    +

    +[#B +

    +

    Footnotes

    diff --git a/org/testdata/misc.org b/org/testdata/misc.org index 864618d..e8813a7 100644 --- a/org/testdata/misc.org +++ b/org/testdata/misc.org @@ -133,6 +133,9 @@ When inserting an image link like [[/home/amos/Pictures/Screenshots/img-2017-09- (shrink-window (- (window-height) 12)) (ansi-term)) #+END_SRC +** misc fuzz / regression / edge case +*** index out of range in headline priority parsing +**** [#B * Footnotes [fn:1] a footnote /with/ *markup* diff --git a/org/testdata/misc.pretty_org b/org/testdata/misc.pretty_org index 4b79542..cc128a3 100644 --- a/org/testdata/misc.pretty_org +++ b/org/testdata/misc.pretty_org @@ -133,6 +133,9 @@ When inserting an image link like [[/home/amos/Pictures/Screenshots/img-2017-09- (shrink-window (- (window-height) 12)) (ansi-term)) #+END_SRC +** misc fuzz / regression / edge case +*** index out of range in headline priority parsing +**** [#B * Footnotes [fn:1] a footnote /with/ *markup*