Skip to content

Index out of bounds at firstpass.rs:1424 #666

Closed

Description

@mgeisler

I tried running the existing parse fuzzer, and found this crash:

thread '<unnamed>' panicked at 'index out of bounds: the len is 14 but the index is 14', /home/mg/src/pulldown-cmark/src/firstpass.rs:1424:13
stack backtrace:
   0: rust_begin_unwind
             at /rustc/6bba061467f7c2cab04b262b95eb67bf89265587/library/std/src/panicking.rs:593:5
   1: core::panicking::panic_fmt
             at /rustc/6bba061467f7c2cab04b262b95eb67bf89265587/library/core/src/panicking.rs:67:14
   2: core::panicking::panic_bounds_check
             at /rustc/6bba061467f7c2cab04b262b95eb67bf89265587/library/core/src/panicking.rs:162:5
   3: core::option::Option<T>::map_or
   4: pulldown_cmark::firstpass::scan_paragraph_interrupt
   5: pulldown_cmark::firstpass::FirstPass::parse_paragraph
   6: pulldown_cmark::firstpass::FirstPass::parse_block
   7: pulldown_cmark::firstpass::FirstPass::run
   8: pulldown_cmark::firstpass::run_first_pass
   9: pulldown_cmark::parse::Parser::new_ext

The input is a file with a lot of null bytes: minimized-from-e9832c8a219680362d96eba6a59a76ace4b3cd40.zip.

Output of `std::fmt::Debug`:

	FuzzingInput {
	    markdown: ".\r> ^](\r\u{c}\r\0\0\r.\r[^\0\0\\\0\0\0^^^^^]",
	    tables: false,
	    footnotes: true,
	    strikethrough: false,
	    tasklists: true,
	    smart_punctuation: false,
	    heading_attributes: false,
	}

Activity

  1. mgeisler commented on Jun 17, 2023

    @mgeisler
    CollaboratorAuthor

    (I'm not able to assign labels to the issues I create, I think I need to be a collaborator on the repository for that.)

  2. raphlinus commented on Jun 17, 2023

    @raphlinus
    Collaborator

    You should be invited now.

  3. mgeisler commented on Jun 17, 2023

    @mgeisler
    CollaboratorAuthor

    The following simple patch might be enough — tests are passing before/after I apply it:

    @@ -1420,9 +1478,10 @@ fn scan_paragraph_interrupt(bytes: &[u8], current_container: bool, gfm_footnote:
             })
             || bytes.starts_with(b"<")
                 && (get_html_end_tag(&bytes[1..]).is_some() || starts_html_block_type_6(&bytes[1..]))
    -        || (gfm_footnote && bytes.starts_with(b"[^") && scan_link_label_rest(std::str::from_utf8(&bytes[2..]).unwrap(), &|_| None).map_or(false, |(len, _)| {
    -            bytes[2 + len] == b':'
    -        }))
    +        || (gfm_footnote
    +            && bytes.starts_with(b"[^")
    +            && scan_link_label_rest(std::str::from_utf8(&bytes[2..]).unwrap(), &|_| None)
    +                .map_or(false, |(len, _)| bytes.get(2 + len) == Some(&b':')))
     }
     
     /// Assumes `text_bytes` is preceded by `<`.
  4. mgeisler commented on Jun 17, 2023

    @mgeisler
    CollaboratorAuthor

    You should be invited now.

    Oh, nice! Thanks 😄

  5. mgeisler commented on Jun 17, 2023

    @mgeisler
    CollaboratorAuthor

    It seems like this line was introduced in #654. @notriddle, does my patch above look good to you? The fuzzer seem stable after I apply it.

  6. added a commit that references this issue on Jun 17, 2023
    01b6446
  7. mgeisler commented on Jun 17, 2023

    @mgeisler
    CollaboratorAuthor

    Let's discuss on #667.

  8. moved this from Todo to Done in pulldown-cmark 0.10on Jun 18, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions