You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
into_offset_iter() panics (Option::unwrap on None, parse.rs:2199) on a 9-character document, no options required #1129
Parser::into_offset_iter() panics on a nine-character document. Plain iteration over the same parser is fine, and no options are required — Options::empty() is enough.
thread 'main' panicked at pulldown-cmark-0.13.4/src/parse.rs:2199:47:
called `Option::unwrap()` on a `None` value
Reproduction
use pulldown_cmark::{Options,Parser};fnmain(){let input = "+\t[\u{0}]:d\n\u{b}";// Fine — two events.println!("plain: {}",Parser::new_ext(input,Options::empty()).count());// Panics.let n = Parser::new_ext(input,Options::empty()).into_offset_iter().count();println!("offsets: {n}");}
Output:
plain: 2
thread 'main' panicked at .../pulldown-cmark-0.13.4/src/parse.rs:2199:47:
called `Option::unwrap()` on a `None` value
The document is a list item containing what looks like a link reference definition with a NUL in its label, followed by a vertical tab:
+\t
list marker and tab
[\u{0}]:d
link reference definition, NUL in the label
\n\u{b}
newline, then U+000B
What narrows it down
Only the offset iterator panics.Parser::next() walks the same document to completion and yields two events; into_offset_iter() panics. That points at the range bookkeeping rather than at block or inline parsing.
No options needed.Options::empty(), ENABLE_STRIKETHROUGH and Options::all() all panic identically, so this is not extension-specific.
The input is minimal. Every single-character deletion I tried stops the panic:
Variant
Result
+\t[\0]:d\n\u{b}
panics
+\t[]:d\n\u{b} (no NUL)
ok
+\t[\0]:d\n (no VT)
ok
+[\0]:d\n\u{b} (no tab)
ok
\t[\0]:d\n\u{b} (no +)
ok
+\t[\0]:\n\u{b} (no destination)
ok
So it needs the list marker, the tab, the NUL in the label, the destination, and the trailing vertical tab together.
Version
pulldown-cmark 0.13.4, Rust 1.90 on Windows 11. Also reproduces on Linux (found there first).
How it was found
A fuzz target over a Markdown editor's segmenting layer, which uses into_offset_iter() to recover byte ranges for every event. libFuzzer reached it in about four minutes; the case above is its minimised output.
Probably not a duplicate, though possibly the same family. #1084 is at parse.rs:2367, needs ENABLE_TASKLISTSandENABLE_STRIKETHROUGH, and panics through push_html — i.e. plain iteration. This one is at 2199, needs no options, and does not panic under plain iteration at all. Both inputs do contain a [...]: link reference definition with a NUL, so a common cause would not be surprising.
Another reproduction of the same panic, with only printable characters and whitespace (no NUL or vertical tab), on 0.13.4:
pulldown_cmark::Parser::new("- [o]:u\n\t").into_offset_iter().count();// panics at parse.rs:2199
pulldown_cmark::Parser::new("- [o]:u\n\t").count();// fine
It's a list item holding only a link reference definition, followed by a whitespace-only line with a tab past the item's indent. The same happens with 1. and * markers, inside a > block quote, after another list item, with CRLF line endings, and with \t\t. We found it by fuzzing random edits in an editor that re-parses on every keystroke; we're guarding it with catch_unwind for now.
The same panic here, and I think it is already fixed on main, just not released. A one-hunk backport to branch_0.13 fixes it, and a regression test is below.
Reproducers (0.13.4; Options::empty(), ENABLE_TABLES and Options::all() behave the same):
use pulldown_cmark::{Options,Parser};fnmain(){for body in["- [o]:u\n\t","> - [o]:u\n> \t","> - [o]:u\n> \u{c}","+\t[\0]:d\n\u{b}",// the body from this issue]{// panics at parse.rs:2199:47: called `Option::unwrap()` on a `None` valuelet _ = Parser::new_ext(body,Options::empty()).into_offset_iter().count();}}
Cause. After a link reference definition, scan_next_line_or_lazy_continuation (firstpass.rs:417 in 0.13.4) takes a line that is white space after its container markers as a lazy continuation. The list item then gets a TightParagraph with no children. OffsetIter::next calls tree.cur().unwrap() on it (parse.rs:2199). #1096 handled the same case in Parser::next by returning None. That avoids the panic, but it ends the whole event stream, which explains the missing closing tags above.
Fix on main.edee73b7 ("Prevent spurious <br> at <p> start after four-space blank line", for #997) ends that paragraph on a blank line (firstpass.rs:526 on main). Bisecting the commits main has over 0.13.4 lands on this commit. Its hunk applies unchanged to branch_0.13, whose firstpass.rs is identical to 0.13.4's:
--- a/pulldown-cmark/src/firstpass.rs+++ b/pulldown-cmark/src/firstpass.rs@@ -421,12 +421,13 @@
let mut line_start = LineStart::new(bytes);
let tree_position = scan_containers(&self.tree, &mut line_start, self.options);
let current_container = tree_position == self.tree.spine_len();
- if !line_start.scan_space(4)+ if (!line_start.scan_space(4)
&& self.scan_paragraph_interrupt(
&bytes[line_start.bytes_scanned()..],
current_container,
tree_position,
- )+ ))+ || scan_blank_line(&bytes[line_start.bytes_scanned()..]).is_some()
{
None
} else {
With it, 0.13.4's own tests still pass. All four bodies above then parse without a panic and give balanced events, both with into_offset_iter() and with plain iteration.
Regression test (appended to tests/html.rs). On 0.13.4 it fails at the first case with right: "<ul>\n<li>"; with the hunk it passes:
#[test]fnwhitespace_line_after_refdef_in_list_item(){for(original, expected)in[("- [o]:u\n\t","<ul>\n<li></li>\n</ul>\n"),("> - [o]:u\n> \t","<blockquote>\n<ul>\n<li></li>\n</ul>\n</blockquote>\n"),("+\t[\0]:d\n\u{b}","<ul>\n<li></li>\n</ul>\n"),]{letmut s = String::new();
html::push_html(&mut s,Parser::new(original));assert_eq!(expected, s,"{original:?}");letmut s = String::new();
html::push_html(&mut s,Parser::new(original).into_offset_iter().map(|(e, _)| e));assert_eq!(expected, s,"{original:?} via into_offset_iter");}}
Could this go into a 0.13.5? One more thing that may explain why fuzzing did not find it: the targets in fuzz/fuzz_targets/ never call into_offset_iter(), and that is the only path that panics here.
Another independent hit, from a coverage-guided fuzz target over into_offset_iter() in an editor (a Markdown math-delimiter scanner), on 0.13.4 with Options::empty(). Two more minimal inputs in the same family. Here the link destination is an unterminated [, and the second line is a single vertical tab or form feed (an exhaustive probe of single trailing ASCII bytes found only these two):
use pulldown_cmark::{Options,Parser};fnmain(){for input in["- [a]:[\n\u{b}","- [a]:[\n\u{c}"]{// plain iteration is fine; the offset iterator panics at parse.rs:2199:47println!("plain events: {}",Parser::new(input).count());assert!(std::panic::catch_unwind(|| {Parser::new_ext(input,Options::empty()).into_offset_iter().count()}).is_err());}}
catch_unwind doesn't help builds with panic = "abort" (our wasm client), so we skip parsing for these inputs until a fix is released. +1 for a 0.13.5 with the backport above.
4. The same panic here, and I think it is already fixed on main, just not released. A one-hunk backport to branch_0.13 fixes it, and a regression test is below.
I agree with @richardguenther - verified with a short, targeted fuzzing session.
Activity
scriswell commentedon Sep 29, 2026
Another reproduction of the same panic, with only printable characters and whitespace (no NUL or vertical tab), on 0.13.4:
It's a list item holding only a link reference definition, followed by a whitespace-only line with a tab past the item's indent. The same happens with
1.and*markers, inside a>block quote, after another list item, with CRLF line endings, and with\t\t. We found it by fuzzing random edits in an editor that re-parses on every keystroke; we're guarding it withcatch_unwindfor now.richardguenther commentedon Oct 16, 2026
The same panic here, and I think it is already fixed on
main, just not released. A one-hunk backport tobranch_0.13fixes it, and a regression test is below.Reproducers (0.13.4;
Options::empty(),ENABLE_TABLESandOptions::all()behave the same):into_offset_iter()Parser/push_htmlbranch_0.13at 21a182d"- [o]:u\n \t"gives<ul>\n<li>with no closing tagsmainat ad1622b<ul>\n<li></li>\n</ul>\nCause. After a link reference definition,
scan_next_line_or_lazy_continuation(firstpass.rs:417in 0.13.4) takes a line that is white space after its container markers as a lazy continuation. The list item then gets aTightParagraphwith no children.OffsetIter::nextcallstree.cur().unwrap()on it (parse.rs:2199). #1096 handled the same case inParser::nextby returningNone. That avoids the panic, but it ends the whole event stream, which explains the missing closing tags above.Fix on
main.edee73b7("Prevent spurious<br>at<p>start after four-space blank line", for #997) ends that paragraph on a blank line (firstpass.rs:526onmain). Bisecting the commitsmainhas over 0.13.4 lands on this commit. Its hunk applies unchanged tobranch_0.13, whosefirstpass.rsis identical to 0.13.4's:With it, 0.13.4's own tests still pass. All four bodies above then parse without a panic and give balanced events, both with
into_offset_iter()and with plain iteration.Regression test (appended to
tests/html.rs). On 0.13.4 it fails at the first case withright: "<ul>\n<li>"; with the hunk it passes:Could this go into a 0.13.5? One more thing that may explain why fuzzing did not find it: the targets in
fuzz/fuzz_targets/never callinto_offset_iter(), and that is the only path that panics here.DanielBoigk commentedon Oct 17, 2026
Another independent hit, from a coverage-guided fuzz target over
into_offset_iter()in an editor (a Markdown math-delimiter scanner), on 0.13.4 withOptions::empty(). Two more minimal inputs in the same family. Here the link destination is an unterminated[, and the second line is a single vertical tab or form feed (an exhaustive probe of single trailing ASCII bytes found only these two):catch_unwinddoesn't help builds withpanic = "abort"(our wasm client), so we skip parsing for these inputs until a fix is released. +1 for a 0.13.5 with the backport above.junkdog commentedon Oct 19, 2026
I agree with @richardguenther - verified with a short, targeted fuzzing session.
Martin1887 commentedon Oct 19, 2026
Fixed by #1021.