facebook / facebook/relay

graphql-syntax: Parser crash parse_document_with_features (assertion failed: start <= end)

Open
#4,579 0 comments 0 reactions 0 assignees View on GitHub
Dominant language
Rust
Stars
19k
Forks
1.9k
PR merge metrics
No merged PRs in 30d

Description

**NOTE**: This bug report is part of a trial for using fuzz-harnesses, see https://github.com/facebook/relay/issues/4566#issuecomment-1883491254 for more context. This bug was found using the fuzz harness in #4565.

## Steps to reproduce
```rust

use arbitrary::Arbitrary;
use common::SourceLocationKey;
use graphql_syntax::parse_document_with_features;
use graphql_syntax::ParserFeatures;

fn main() {
let _res = parse_document_with_features( "{c;:(;", SourceLocationKey::Generated, ParserFeatures { fragment_argument_capability: None});
};
```

## My approximation of the information that you'll get from google/oss-fuzz if this where integrated.
### Stacktrace and error input
```
INFO: Running with entropic power schedule (0xFF, 100).
INFO: Seed: 1087352834
INFO: Loaded 1 modules (288424 inline 8-bit counters): 288424 [0x5557f00f0100, 0x5557f01367a8),
INFO: Loaded 1 PC tables (288424 PCs): 288424 [0x5557f01367a8,0x5557f059d228),
INFO: 721 files found in /home/nathaniel/projects/github.com/silvergasp/relay/compiler/crates/graphql-syntax/fuzz/corpus/fuzz_parser
INFO: -max_len is not provided; libFuzzer will not generate inputs larger than 4096 bytes
INFO: seed corpus: files: 721 min: 4b max: 20b total: 7878b rss: 45Mb
#761 INITED cov: 2578 ft: 5728 corp: 605/6767b exec/s: 0 rss: 70Mb
#805 NEW cov: 2578 ft: 5729 corp: 606/6780b lim: 24 exec/s: 0 rss: 71Mb L: 13/20 MS: 3 ChangeBit-ChangeByte-ChangeByte-
#906 NEW cov: 2578 ft: 5730 corp: 607/6794b lim: 24 exec/s: 0 rss: 71Mb L: 14/20 MS: 1 ChangeByte-
thread '' panicked at /home/nathaniel/projects/github.com/silvergasp/relay/compiler/crates/common/src/span.rs:22:9:
assertion failed: start <= end
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
==451844== ERROR: libFuzzer: deadly signal
#0 0x5557ef047311 in __sanitizer_print_stack_trace /rustc/llvm/src/llvm-project/compiler-rt/lib/asan/asan_stack.cpp:87:3
#1 0x5557efce6049 in fuzzer::PrintStackTrace() /home/nathaniel/.cargo/registry/src/index.crates.io-6f17d22bba15001f/libfuzzer-sys-0.4.7/libfuzzer/FuzzerUtil.cpp:210:38
#2 0x5557efcd1415 in fuzzer::Fuzzer::CrashCallback() /home/nathaniel/.cargo/registry/src/index.crates.io-6f17d22bba15001f/libfuzzer-sys-0.4.7/libfuzzer/FuzzerLoop.cpp:233:18
#3 0x5557efcd1415 in fuzzer::Fuzzer::CrashCallback() /home/nathaniel/.cargo/registry/src/index.crates.io-6f17d22bba15001f/libfuzzer-sys-0.4.7/libfuzzer/FuzzerLoop.cpp:228:6
#4 0x7f59ebe51d9f (/nix/store/whypqfa83z4bsn43n4byvmw80n4mg3r8-glibc-2.37-45/lib/libc.so.6+0x38d9f) (BuildId: 2b9ebcc534a497a5e424c017f310e087ec14b7b6)
#5 0x7f59ebea0b1b in __pthread_kill_implementation (/nix/store/whypqfa83z4bsn43n4byvmw80n4mg3r8-glibc-2.37-45/lib/libc.so.6+0x87b1b) (BuildId: 2b9ebcc534a497a5e424c017f310e087ec14b7b6)
#6 0x7f59ebe51cf5 in gsignal (/nix/store/whypqfa83z4bsn43n4byvmw80n4mg3r8-glibc-2.37-45/lib/libc.so.6+0x38cf5) (BuildId: 2b9ebcc534a497a5e424c017f310e087ec14b7b6)
#7 0x7f59ebe3b8b9 in abort (/nix/store/whypqfa83z4bsn43n4byvmw80n4mg3r8-glibc-2.37-45/lib/libc.so.6+0x228b9) (BuildId: 2b9ebcc534a497a5e424c017f310e087ec14b7b6)
#8 0x5557efd97856 in std::sys::unix::abort_internal::hb88d147b24444ccb /rustc/75c68cfd2b9870f2953b62d250bd7d0564a7b56d/library/std/src/sys/unix/mod.rs:375:14
#9 0x5557eef9dde6 in std::process::abort::h48da3a1587f663a3 /rustc/75c68cfd2b9870f2953b62d250bd7d0564a7b56d/library/std/src/process.rs:2279:5
#10 0x5557efccb664 in libfuzzer_sys::initialize::_$u7b$$u7b$closure$u7d$$u7d$::hb85733ac7a5d2d57 /home/nathaniel/.cargo/registry/src/index.crates.io-6f17d22bba15001f/libfuzzer-sys-0.4.7/src/lib.rs:91:9
#11 0x5557efd8c325 in _$LT$alloc..boxed..Box$LT$F$C$A$GT$$u20$as$u20$core..ops..function..Fn$LT$Args$GT$$GT$::call::h1171429379e58ebd /rustc/75c68cfd2b9870f2953b62d250bd7d0564a7b56d/library/alloc/src/boxed.rs:2030:9
#12 0x5557efd8c325 in std::panicking::rust_panic_with_hook::he8cd11bc79b74e48 /rustc/75c68cfd2b9870f2953b62d250bd7d0564a7b56d/library/std/src/panicking.rs:783:13
#13 0x5557efd8c038 in std::panicking::begin_panic_handler::_$u7b$$u7b$closure$u7d$$u7d$::he1868b3475576648 /rustc/75c68cfd2b9870f2953b62d250bd7d0564a7b56d/library/std/src/panicking.rs:649:13
#14 0x5557efd895d5 in std::sys_common::backtrace::__rust_end_short_backtrace::h9210389720f5c16a /rustc/75c68cfd2b9870f2953b62d250bd7d0564a7b56d/library/std/src/sys_common/backtrace.rs:171:18
#15 0x5557efd8bdcf in rust_begin_unwind /rustc/75c68cfd2b9870f2953b62d250bd7d0564a7b56d/library/std/src/panicking.rs:645:5
#16 0x5557eefa12c4 in core::panicking::panic_fmt::hfbd09a125111b8b4 /rustc/75c68cfd2b9870f2953b62d250bd7d0564a7b56d/library/core/src/panicking.rs:72:14
#17 0x5557eefa1382 in core::panicking::panic::h8ed89a8593b3dafc /rustc/75c68cfd2b9870f2953b62d250bd7d0564a7b56d/library/core/src/panicking.rs:144:5
#18 0x5557ef3f8765 in common::span::Span::new::hfbf00cbc4dc577ed /home/nathaniel/projects/github.com/silvergasp/relay/compiler/crates/common/src/span.rs:22:9
#19 0x5557ef289592 in graphql_syntax::parser::Parser::parse_optional_arguments::hb37031eb1f33ce02 /home/nathaniel/projects/github.com/silvergasp/relay/compiler/crates/graphql-syntax/src/parser.rs:1535:28
#20 0x5557ef28277c in graphql_syntax::parser::Parser::parse_field::h8423899e229a958c /home/nathaniel/projects/github.com/silvergasp/relay/compiler/crates/graphql-syntax/src/parser.rs:1330:25
#21 0x5557ef281598 in graphql_syntax::parser::Parser::parse_selection::hcb3b76fb805e8c24 /home/nathaniel/projects/github.com/silvergasp/relay/compiler/crates/graphql-syntax/src/parser.rs:1274:38
#22 0x5557ef2a7818 in core::ops::function::Fn::call::h93758d54f67ebf20 /rustc/75c68cfd2b9870f2953b62d250bd7d0564a7b56d/library/core/src/ops/function.rs:79:5
#23 0x5557ef2a7818 in graphql_syntax::parser::Parser::parse_delimited_nonempty_list::h3c059ae2057dc45f /home/nathaniel/projects/github.com/silvergasp/relay/compiler/crates/graphql-syntax/src/parser.rs:1971:24
#24 0x5557ef27933e in graphql_syntax::parser::Parser::parse_selections::hb751b851ff8c9d50 /home/nathaniel/projects/github.com/silvergasp/relay/compiler/crates/graphql-syntax/src/parser.rs:1259:9
#25 0x5557ef27933e in graphql_syntax::parser::Parser::parse_operation_definition::h03c6c00cd88e6436 /home/nathaniel/projects/github.com/silvergasp/relay/compiler/crates/graphql-syntax/src/parser.rs:1067:30
#26 0x5557ef25db57 in graphql_syntax::parser::Parser::parse_executable_definition::h40bfc86e8b5c1bec /home/nathaniel/projects/github.com/silvergasp/relay/compiler/crates/graphql-syntax/src/parser.rs:326:17
#27 0x5557ef25cc6d in graphql_syntax::parser::Parser::parse_definition::hf2109a6b590c7ceb /home/nathaniel/projects/github.com/silvergasp/relay/compiler/crates/graphql-syntax/src/parser.rs:275:17
#28 0x5557ef29bc43 in graphql_syntax::parser::Parser::parse_document_impl::_$u7b$$u7b$closure$u7d$$u7d$::hf1bea19df1051c93 /home/nathaniel/projects/github.com/silvergasp/relay/compiler/crates/graphql-syntax/src/parser.rs:225:72
#29 0x5557ef29bc43 in graphql_syntax::parser::Parser::parse_list::hcb344bcb0ffa867e /home/nathaniel/projects/github.com/silvergasp/relay/compiler/crates/graphql-syntax/src/parser.rs:1908:24
#30 0x5557ef255d87 in graphql_syntax::parser::Parser::parse_document_impl::h417a7686573d2988 /home/nathaniel/projects/github.com/silvergasp/relay/compiler/crates/graphql-syntax/src/parser.rs:225:27
#31 0x5557ef255d87 in graphql_syntax::parser::Parser::parse_document::hacae4139e593fa4d /home/nathaniel/projects/github.com/silvergasp/relay/compiler/crates/graphql-syntax/src/parser.rs:113:24
#32 0x5557ef2b887b in graphql_syntax::parse_document_with_features::hc35ddc8d183e458d /home/nathaniel/projects/github.com/silvergasp/relay/compiler/crates/graphql-syntax/src/lib.rs:51:5
#33 0x5557ef0ba3a3 in fuzz_parser::_::__libfuzzer_sys_run::hbcfe1f90ad32aaed /home/nathaniel/projects/github.com/silvergasp/relay/compiler/crates/graphql-syntax/fuzz/fuzz_targets/fuzz_parser.rs:20:11
#34 0x5557ef0b93db in rust_fuzzer_test_input /home/nathaniel/.cargo/registry/src/index.crates.io-6f17d22bba15001f/libfuzzer-sys-0.4.7/src/lib.rs:297:60
#35 0x5557efcc5d38 in libfuzzer_sys::test_input_wrap::_$u7b$$u7b$closure$u7d$$u7d$::hc1ebeb1e5434c8ae /home/nathaniel/.cargo/registry/src/index.crates.io-6f17d22bba15001f/libfuzzer-sys-0.4.7/src/lib.rs:61:9
#36 0x5557efcc5d38 in std::panicking::try::do_call::h6689f7f2ac49fcc9 /rustc/75c68cfd2b9870f2953b62d250bd7d0564a7b56d/library/std/src/panicking.rs:552:40
#37 0x5557efccb877 in __rust_try libfuzzer_sys.16b8e11d1125706d-cgu.0
#38 0x5557efcca931 in std::panicking::try::hd5c10ed80d3d2169 /rustc/75c68cfd2b9870f2953b62d250bd7d0564a7b56d/library/std/src/panicking.rs:516:19
#39 0x5557efcca931 in std::panic::catch_unwind::h15c7e6ee02f461d0 /rustc/75c68cfd2b9870f2953b62d250bd7d0564a7b56d/library/std/src/panic.rs:142:14
#40 0x5557efcca931 in LLVMFuzzerTestOneInput /home/nathaniel/.cargo/registry/src/index.crates.io-6f17d22bba15001f/libfuzzer-sys-0.4.7/src/lib.rs:59:22
#41 0x5557efcd1949 in fuzzer::Fuzzer::ExecuteCallback(unsigned char const*, unsigned long) /home/nathaniel/.cargo/registry/src/index.crates.io-6f17d22bba15001f/libfuzzer-sys-0.4.7/libfuzzer/FuzzerLoop.cpp:612:15
#42 0x5557efcd9015 in fuzzer::Fuzzer::RunOne(unsigned char const*, unsigned long, bool, fuzzer::InputInfo*, bool, bool*) /home/nathaniel/.cargo/registry/src/index.crates.io-6f17d22bba15001f/libfuzzer-sys-0.4.7/libfuzzer/FuzzerLoop.cpp:514:22
#43 0x5557efcd9ed2 in fuzzer::Fuzzer::MutateAndTestOne() /home/nathaniel/.cargo/registry/src/index.crates.io-6f17d22bba15001f/libfuzzer-sys-0.4.7/libfuzzer/FuzzerLoop.cpp:758:25
#44 0x5557efcdacb7 in fuzzer::Fuzzer::Loop(std::vector>&) /home/nathaniel/.cargo/registry/src/index.crates.io-6f17d22bba15001f/libfuzzer-sys-0.4.7/libfuzzer/FuzzerLoop.cpp:903:21
#45 0x5557efcfadf1 in fuzzer::FuzzerDriver(int*, char***, int (*)(unsigned char const*, unsigned long)) /home/nathaniel/.cargo/registry/src/index.crates.io-6f17d22bba15001f/libfuzzer-sys-0.4.7/libfuzzer/FuzzerDriver.cpp:912:10
#46 0x5557eefa1cd2 in main /home/nathaniel/.cargo/registry/src/index.crates.io-6f17d22bba15001f/libfuzzer-sys-0.4.7/libfuzzer/FuzzerMain.cpp:20:30
#47 0x7f59ebe3cb0d in __libc_start_call_main (/nix/store/whypqfa83z4bsn43n4byvmw80n4mg3r8-glibc-2.37-45/lib/libc.so.6+0x23b0d) (BuildId: 2b9ebcc534a497a5e424c017f310e087ec14b7b6)
#48 0x7f59ebe3cbc8 in __libc_start_main@GLIBC_2.2.5 (/nix/store/whypqfa83z4bsn43n4byvmw80n4mg3r8-glibc-2.37-45/lib/libc.so.6+0x23bc8) (BuildId: 2b9ebcc534a497a5e424c017f310e087ec14b7b6)
#49 0x5557eefa1e34 in _start (/home/nathaniel/projects/github.com/silvergasp/relay/compiler/crates/graphql-syntax/fuzz/target/x86_64-unknown-linux-gnu/release/fuzz_parser+0x786e34)

NOTE: libFuzzer has rudimentary signal handlers.
Combine libFuzzer with AddressSanitizer or similar for better crash reports.
SUMMARY: libFuzzer: deadly signal
MS: 3 CopyPart-ShuffleBytes-ChangeByte-; base unit: d60d045c40884a29494d7afb7f0e418046f2c0f4
0x7b,0x63,0x3b,0x3a,0x28,0x3b,0xb3,0x28,0x30,0x75,0x32,0x28,0x30,0x75,0xd,
{c;:(;\263(0u2(0u\015
artifact_prefix='/home/nathaniel/projects/github.com/silvergasp/relay/compiler/crates/graphql-syntax/fuzz/artifacts/fuzz_parser/'; Test unit written to /home/nathaniel/projects/github.com/silvergasp/relay/compiler/crates/graphql-syntax/fuzz/artifacts/fuzz_parser/crash-23745e1d4033d739b1ea52eb0f97ecb19f9c59ef
Base64: e2M7Oig7sygwdTIoMHUN

────────────────────────────────────────────────────────────────────────────────

Failing input:

fuzz/artifacts/fuzz_parser/crash-23745e1d4033d739b1ea52eb0f97ecb19f9c59ef

Output of `std::fmt::Debug`:

Ctx {
source: "{c;:(;",
features: ParserFeatures {
fragment_argument_capability: OnlyFragmentVariableDefinitions,
},
}

Reproduce with:

cargo fuzz run fuzz_parser fuzz/artifacts/fuzz_parser/crash-23745e1d4033d739b1ea52eb0f97ecb19f9c59ef

Minimize test case with:

cargo fuzz tmin fuzz_parser fuzz/artifacts/fuzz_parser/crash-23745e1d4033d739b1ea52eb0f97ecb19f9c59ef

────────────────────────────────────────────────────────────────────────────────

```

### Crash file
OSS-fuzz will automatically minimise the test-case so there is no need to run `cargo fuzz tmin`.
[crash-23745e1d4033d739b1ea52eb0f97ecb19f9c59ef.txt](https://github.com/facebook/relay/files/13892829/crash-23745e1d4033d739b1ea52eb0f97ecb19f9c59ef.txt)

To reproduce using cargo fuzz simply run;
```
cd compiler/crates/graphql-syntax
cargo fuzz run fuzz_parser path/to/downloaded/crash-23745e1d4033d739b1ea52eb0f97ecb19f9c59ef.txt
```

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.