Skip to content

parsing certain invalid code in debug profile leads to "assertion failed: self.start <= self.end" #22515

@Benjins

Description

@Benjins

Here is a simple reproducer in Rust:

fn main() {
    let allocator = oxc_allocator::Allocator::default();
    let source_type = oxc_span::SourceType::default();
    let _ = oxc_parser::Parser::new(&allocator, "class extends,{", source_type).parse();
}

The specific minimised repro input:

class extends,{

When compiled and run in debug mode (or with debug assertions enabled), it gives this error:

thread 'main' (500479) panicked at ~/oxc/crates/oxc_span/src/span.rs:156:9:
assertion failed: self.start <= self.end

and the callstack for it:

   3: <oxc_span::span::Span>::size
             at ~/oxc/crates/oxc_span/src/span.rs:156:9
   4: <miette::protocol::SourceSpan as core::convert::From<oxc_span::span::Span>>::from
             at ~/oxc/crates/oxc_span/src/span.rs:566:63
   5: <oxc_span::span::Span as core::convert::Into<miette::protocol::SourceSpan>>::into
             at ~/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/core/src/convert/mod.rs:779:9
   6: <miette::protocol::LabeledSpan>::new_with_span::<oxc_span::span::Span>
             at ~/.cargo/registry/src/index.crates.io-1949cf8c6b5b557f/oxc-miette-2.7.1/src/protocol.rs:290:34
   7: <miette::protocol::LabeledSpan>::underline::<oxc_span::span::Span>
             at ~/.cargo/registry/src/index.crates.io-1949cf8c6b5b557f/oxc-miette-2.7.1/src/protocol.rs:356:9
   8: <miette::protocol::LabeledSpan as core::convert::From<oxc_span::span::Span>>::from
             at ~/oxc/crates/oxc_span/src/span.rs:572:9
   9: <oxc_span::span::Span as core::convert::Into<miette::protocol::LabeledSpan>>::into
             at ~/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/core/src/convert/mod.rs:779:9
  10: <oxc_diagnostics::OxcDiagnostic>::with_label::<oxc_span::span::Span>
             at ~/oxc/crates/oxc_diagnostics/src/lib.rs:313:45
  11: oxc_parser::diagnostics::classes_can_only_extend_single_class
             at ~/oxc/crates/oxc_parser/src/diagnostics.rs:340:10
  12: <oxc_parser::ParserImpl<oxc_parser::config::NoTokensParserConfig>>::parse_class
             at ~/oxc/crates/oxc_parser/src/js/class.rs:93:28
  13: <oxc_parser::ParserImpl<oxc_parser::config::NoTokensParserConfig>>::parse_class_declaration
             at ~/oxc/crates/oxc_parser/src/js/class.rs:43:14
  14: <oxc_parser::ParserImpl<oxc_parser::config::NoTokensParserConfig>>::parse_class_statement
             at ~/oxc/crates/oxc_parser/src/js/class.rs:26:25
  15: <oxc_parser::ParserImpl<oxc_parser::config::NoTokensParserConfig>>::parse_statement_list_item
             at ~/oxc/crates/oxc_parser/src/js/statement.rs:129:33
  16: <oxc_parser::ParserImpl<oxc_parser::config::NoTokensParserConfig>>::parse_directives_and_statements
             at ~/oxc/crates/oxc_parser/src/js/statement.rs:70:29
  17: <oxc_parser::ParserImpl<oxc_parser::config::NoTokensParserConfig>>::parse_program
             at ~/oxc/crates/oxc_parser/src/lib.rs:775:49
  18: <oxc_parser::ParserImpl<oxc_parser::config::NoTokensParserConfig>>::parse
             at ~/oxc/crates/oxc_parser/src/lib.rs:672:32
  19: oxc_parser::parser_parse::parse_with_no_tokens_config
             at ~/oxc/crates/oxc_parser/src/lib.rs:487:10
  20: <oxc_parser::Parser>::parse
             at ~/oxc/crates/oxc_parser/src/lib.rs:349:17

Since this is invalid code as input, it should give some user-facing error, and indeed it does in release mode. The latest oxlint reports:

  × Unexpected token
   ╭─[test.js:1:14]
 1 │ class extends,{
   ·              ─
   ╰────

Tested against c9f506e which is the latest main commit

For some context: this was found with a fuzzer, if that affects triage/priority

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    Priority

    None yet

    Effort

    None yet

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions