johannhof / markdown.rs

Rust Markdown parsing library
Apache License 2.0
136 stars 44 forks source link

thread 'main' panicked at 'index out of bounds: the len is 1 but the index is 1' #45

Open sigaloid opened 3 years ago

sigaloid commented 3 years ago
fn main() {
    println!("{}", markdown::to_html("[1]:"));
}
stack backtrace:
   0:     0x55f99998445c - std::backtrace_rs::backtrace::libunwind::trace::hc6c3491277866fea
                               at /rustc/efd0483949496b067cd5f7569d1b28cd3d5d3c72/library/std/src/../../backtrace/src/backtrace/libunwind.rs:93:5
   1:     0x55f99998445c - std::backtrace_rs::backtrace::trace_unsynchronized::h4524f073368a5b13
                               at /rustc/efd0483949496b067cd5f7569d1b28cd3d5d3c72/library/std/src/../../backtrace/src/backtrace/mod.rs:66:5
   2:     0x55f99998445c - std::sys_common::backtrace::_print_fmt::h0d0cace6159902af
                               at /rustc/efd0483949496b067cd5f7569d1b28cd3d5d3c72/library/std/src/sys_common/backtrace.rs:67:5
   3:     0x55f99998445c - <std::sys_common::backtrace::_print::DisplayBacktrace as core::fmt::Display>::fmt::h3e6af6f05919a7fc
                               at /rustc/efd0483949496b067cd5f7569d1b28cd3d5d3c72/library/std/src/sys_common/backtrace.rs:46:22
   4:     0x55f9999a029c - core::fmt::write::h72801a82c94e6ff1
                               at /rustc/efd0483949496b067cd5f7569d1b28cd3d5d3c72/library/core/src/fmt/mod.rs:1163:17
   5:     0x55f999981855 - std::io::Write::write_fmt::ha4f5d34aaccbac84
                               at /rustc/efd0483949496b067cd5f7569d1b28cd3d5d3c72/library/std/src/io/mod.rs:1696:15
   6:     0x55f999985c90 - std::sys_common::backtrace::_print::heed69f5ce9a8e189
                               at /rustc/efd0483949496b067cd5f7569d1b28cd3d5d3c72/library/std/src/sys_common/backtrace.rs:49:5
   7:     0x55f999985c90 - std::sys_common::backtrace::print::h5f3918bd80c09252
                               at /rustc/efd0483949496b067cd5f7569d1b28cd3d5d3c72/library/std/src/sys_common/backtrace.rs:36:9
   8:     0x55f999985c90 - std::panicking::default_hook::{{closure}}::h5af30648530eb3d0
                               at /rustc/efd0483949496b067cd5f7569d1b28cd3d5d3c72/library/std/src/panicking.rs:210:50
   9:     0x55f99998583b - std::panicking::default_hook::he88d5fb1ba1b4c19
                               at /rustc/efd0483949496b067cd5f7569d1b28cd3d5d3c72/library/std/src/panicking.rs:227:9
  10:     0x55f999986474 - std::panicking::rust_panic_with_hook::h01febc308b2b313b
                               at /rustc/efd0483949496b067cd5f7569d1b28cd3d5d3c72/library/std/src/panicking.rs:602:17
  11:     0x55f999985f20 - std::panicking::begin_panic_handler::{{closure}}::h24a6d13f5560b71f
                               at /rustc/efd0483949496b067cd5f7569d1b28cd3d5d3c72/library/std/src/panicking.rs:499:13
  12:     0x55f999984904 - std::sys_common::backtrace::__rust_end_short_backtrace::h3e2917f0da9fbc5c
                               at /rustc/efd0483949496b067cd5f7569d1b28cd3d5d3c72/library/std/src/sys_common/backtrace.rs:139:18
  13:     0x55f999985e89 - rust_begin_unwind
                               at /rustc/efd0483949496b067cd5f7569d1b28cd3d5d3c72/library/std/src/panicking.rs:495:5
  14:     0x55f99999f301 - core::panicking::panic_fmt::h7b8580d81fcbbacd
                               at /rustc/efd0483949496b067cd5f7569d1b28cd3d5d3c72/library/core/src/panicking.rs:107:14
  15:     0x55f99999f2c2 - core::panicking::panic_bounds_check::h63650a5dfc9aa86f
                               at /rustc/efd0483949496b067cd5f7569d1b28cd3d5d3c72/library/core/src/panicking.rs:76:5
  16:     0x55f999776020 - markdown::parser::block::link_reference::parse_link_reference::hd3bd27b198043088
                               at /home/matt/markdown.rs/src/parser/block/link_reference.rs:27:92
  17:     0x55f99979771b - markdown::parser::block::parse_block::hb08ec6906bb8cd58
                               at /home/matt/markdown.rs/src/parser/block/mod.rs:72:5
  18:     0x55f999796b79 - markdown::parser::block::parse_blocks::h86e17ab619765b8e
                               at /home/matt/markdown.rs/src/parser/block/mod.rs:29:15
  19:     0x55f999784baa - markdown::parser::parse::h3ddeb142d91fbce2
                               at /home/matt/markdown.rs/src/parser/mod.rs:79:5
  20:     0x55f999797d12 - markdown::to_html::he015686c68a8c6ca
                               at /home/matt/markdown.rs/src/lib.rs:26:18
  21:     0x55f99977236e - markdown_fuzz::main::hc09ef24e8dba5dfa
                               at /home/matt/rust/markdown-fuzz/src/main.rs:2:20
  22:     0x55f99977219b - core::ops::function::FnOnce::call_once::heeb57c811752bb01
                               at /rustc/efd0483949496b067cd5f7569d1b28cd3d5d3c72/library/core/src/ops/function.rs:227:5
  23:     0x55f99977245e - std::sys_common::backtrace::__rust_begin_short_backtrace::h6d2d965499d20144
                               at /rustc/efd0483949496b067cd5f7569d1b28cd3d5d3c72/library/std/src/sys_common/backtrace.rs:123:18
  24:     0x55f999772261 - std::rt::lang_start::{{closure}}::h4b41d489adee795a
                               at /rustc/efd0483949496b067cd5f7569d1b28cd3d5d3c72/library/std/src/rt.rs:146:18
  25:     0x55f999983cf1 - core::ops::function::impls::<impl core::ops::function::FnOnce<A> for &F>::call_once::h6743157f0325d450
                               at /rustc/efd0483949496b067cd5f7569d1b28cd3d5d3c72/library/core/src/ops/function.rs:259:13
  26:     0x55f999983cf1 - std::panicking::try::do_call::hc65378359d322d46
                               at /rustc/efd0483949496b067cd5f7569d1b28cd3d5d3c72/library/std/src/panicking.rs:403:40
  27:     0x55f999983cf1 - std::panicking::try::h52b83ca0140efb28
                               at /rustc/efd0483949496b067cd5f7569d1b28cd3d5d3c72/library/std/src/panicking.rs:367:19
  28:     0x55f999983cf1 - std::panic::catch_unwind::h0ba25f4b0d3448dc
                               at /rustc/efd0483949496b067cd5f7569d1b28cd3d5d3c72/library/std/src/panic.rs:133:14
  29:     0x55f999983cf1 - std::rt::lang_start_internal::{{closure}}::ha65f28100c5ad390
                               at /rustc/efd0483949496b067cd5f7569d1b28cd3d5d3c72/library/std/src/rt.rs:128:48
  30:     0x55f999983cf1 - std::panicking::try::do_call::h5db5edfaf5b749d9
                               at /rustc/efd0483949496b067cd5f7569d1b28cd3d5d3c72/library/std/src/panicking.rs:403:40
  31:     0x55f999983cf1 - std::panicking::try::h62409771d6cd0419
                               at /rustc/efd0483949496b067cd5f7569d1b28cd3d5d3c72/library/std/src/panicking.rs:367:19
  32:     0x55f999983cf1 - std::panic::catch_unwind::h386261fb8f018fab
                               at /rustc/efd0483949496b067cd5f7569d1b28cd3d5d3c72/library/std/src/panic.rs:133:14
  33:     0x55f999983cf1 - std::rt::lang_start_internal::h699f3530566c1833
                               at /rustc/efd0483949496b067cd5f7569d1b28cd3d5d3c72/library/std/src/rt.rs:128:20
  34:     0x55f999772230 - std::rt::lang_start::hc9e802c64c904af3
                               at /rustc/efd0483949496b067cd5f7569d1b28cd3d5d3c72/library/std/src/rt.rs:145:17
  35:     0x55f99977244c - main
  36:     0x7fe4173f5b25 - __libc_start_main
  37:     0x55f99977209e - _start
  38:                0x0 - <unknown>

Problem is likely here: https://github.com/johannhof/markdown.rs/blob/master/src/parser/block/link_reference.rs#L27. I'd simply wrap it in an if lines.len() > 1 but I don't know a whole lot about the internals here and that might simply make it output no text whatsoever