Skip to content

Unsafe unwrap in parser #363

Closed
Closed

Description

@RadicalZephyr

Found with the new fuzz testing setup!

This input export\x09AA causes the Lexer to fail.

extern crate just;

fn lex_and_parse<'a>(input: &'a str) -> Result<(), just::CompilationError<'a>> {
  let tokens = just::Lexer::lex(input)?;
  let parser = just::Parser::new(input, tokens);
  let _justfile = parser.justfile()?;
  Ok(())
}

fn main() {
  let input = "export	AA";
  lex_and_parse(&input);
}

Activity

  1. casey commented on Oct 13, 2018

    @casey
    Owner

    Awesome, nice find!

    The parser uses an itertools adapter that allows putting items back into an iterator. However, if you put back two items in a row, it overwrites the previous item. The bug was caused by removing and putting back an Eof token, and then putting back another token, overwriting the Eof token. The parser assumes that it will never advance past the last token, but since the Eof token was overwritten, it does so and crashes.

  2. casey commented on Oct 13, 2018

    @casey
    Owner

    I'm surprised that nobody ever hit this organically!

  3. added a commit that references this issue on Oct 13, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions