Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

GFM with allow_dangerous_html panics when a tag contains a newline after its name #80

Closed
sornas opened this issue Sep 9, 2023 · 4 comments

Comments

@sornas
Copy link

sornas commented Sep 9, 2023

fn main() {
    let source = r#"
<div
>
>/div>
    "#;
    let _md = markdown::to_html_with_options(source, &markdown::Options {
        parse: markdown::ParseOptions::gfm(),
        compile: markdown::CompileOptions {
            allow_dangerous_html: true,
            ..markdown::CompileOptions::gfm()
        },
    }).unwrap();
}

The above code panics in version 1.0.0-alpha.12 at

matches!(bytes[name_end], b'\t' | b'\n' | 12 /* `\f` */ | b'\r' | b' ' | b'/' | b'>') &&

Here's the full RUST_BACKTRACE=1:

thread 'main' panicked at 'index out of bounds: the len is 4 but the index is 4', /home/gustav/.cargo/registry/src/index.crates.io-6f17d22bba15001f/markdown-1.0.0-alpha.12/src/util/gfm_tagfilter.rs:55:26
stack backtrace:
   0: rust_begin_unwind
             at /rustc/5680fa18feaa87f3ff04063800aec256c3d4b4be/library/std/src/panicking.rs:593:5
   1: core::panicking::panic_fmt
             at /rustc/5680fa18feaa87f3ff04063800aec256c3d4b4be/library/core/src/panicking.rs:67:14
   2: core::panicking::panic_bounds_check
             at /rustc/5680fa18feaa87f3ff04063800aec256c3d4b4be/library/core/src/panicking.rs:162:5
   3: markdown::util::gfm_tagfilter::gfm_tagfilter
             at /home/gustav/.cargo/registry/src/index.crates.io-6f17d22bba15001f/markdown-1.0.0-alpha.12/src/util/gfm_tagfilter.rs:55:26
   4: markdown::to_html::on_exit_html_data
             at /home/gustav/.cargo/registry/src/index.crates.io-6f17d22bba15001f/markdown-1.0.0-alpha.12/src/to_html.rs:1304:17
   5: markdown::to_html::exit
             at /home/gustav/.cargo/registry/src/index.crates.io-6f17d22bba15001f/markdown-1.0.0-alpha.12/src/to_html.rs:426:52
   6: markdown::to_html::handle
             at /home/gustav/.cargo/registry/src/index.crates.io-6f17d22bba15001f/markdown-1.0.0-alpha.12/src/to_html.rs:308:9
   7: markdown::to_html::compile
             at /home/gustav/.cargo/registry/src/index.crates.io-6f17d22bba15001f/markdown-1.0.0-alpha.12/src/to_html.rs:283:13
   8: markdown::to_html_with_options
             at /home/gustav/.cargo/registry/src/index.crates.io-6f17d22bba15001f/markdown-1.0.0-alpha.12/src/lib.rs:125:8
   9: markdown_repro::main
             at ./src/main.rs:7:15
  10: core::ops::function::FnOnce::call_once
             at /rustc/5680fa18feaa87f3ff04063800aec256c3d4b4be/library/core/src/ops/function.rs:250:5
@wooorm wooorm closed this as completed in 077ef89 Sep 9, 2023
@wooorm
Copy link
Owner

wooorm commented Sep 9, 2023

Thanks!

@wooorm
Copy link
Owner

wooorm commented Sep 9, 2023

released!

@sornas
Copy link
Author

sornas commented Sep 10, 2023

Awesome, thanks! Although you forgot a print :)

println!("{:?}, {:?}, {:?}", name_start, name_end, bytes);

@wooorm
Copy link
Owner

wooorm commented Sep 20, 2023

Thanks

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants