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

lexer fails to lex string values with escaped characters #227

Closed
garypen opened this issue May 17, 2022 · 2 comments · Fixed by #228
Closed

lexer fails to lex string values with escaped characters #227

garypen opened this issue May 17, 2022 · 2 comments · Fixed by #228
Assignees
Labels
apollo-parser bug Something isn't working

Comments

@garypen
Copy link
Contributor

garypen commented May 17, 2022

Description

See apollographql/router#1065

Steps to reproduce

It's difficult to reproduce in the router, but I wrote a program to demonstrate the issue in the parser.

fn main() {
    use apollo_parser::Parser;

    let input = r#"mutation {
            createStore(draft: {
              name: [{ locale: "en", value: "\"my store\"" }]
            }) {
              name(locale: "en")
            }
          }"#;
    let parser = Parser::new(input);
    let ast = parser.parse(); <- This will never return until memory exhausted.
}

Expected result

If mutation is valid it should parse. If not, fail with error(s).

Actual result

Never returns until memory exhausted.

Environment

  • Operating system and version: Mac OS X
  • Shell (bash/zsh/powershell): zsh
  • apollo-rs crate: apollo-parser
  • Crate version: 0.2.5
@garypen garypen added bug Something isn't working triage labels May 17, 2022
@garypen
Copy link
Contributor Author

garypen commented May 17, 2022

Additional information. I dug into this a little bit and found that the error was manifesting here:

diff --git a/crates/apollo-parser/src/parser/grammar/value.rs b/crates/apollo-parser/src/parser/grammar/value.rs
index 667d668..ed12916 100644
--- a/crates/apollo-parser/src/parser/grammar/value.rs
+++ b/crates/apollo-parser/src/parser/grammar/value.rs
@@ -50,7 +50,10 @@ pub(crate) fn value(p: &mut Parser) {
         }
         Some(T!['[']) => list_value(p),
         Some(T!['{']) => object_value(p),
-        _ => p.err("expected a valid Value"),
+        _ => {
+            eprintln!("we expected a valid value, but got nonsense");
+            p.err_and_pop("expected a valid Value")
+        }
     }
 }
 /// See: https://spec.graphql.org/October2021/#EnumValue

We never seem to realise that we are out of errors. If I change p.err() to p.err_and_pop(), then it works for the example program, but hacking around with the input makes it fairly easy to crash the program.

@lrlna lrlna changed the title mutation parsing results in memory exhaustion lexer fails to lex string values with escaped characters May 23, 2022
@lrlna
Copy link
Member

lrlna commented May 24, 2022

@garypen you can update to [email protected] for a fix.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
apollo-parser bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants