integer overflow in parser angle bracket handling
Nobody has claimed this yet.
- Dominant language
- Rust
- Stars
- 119k
- Forks
- 16.1k
- PR merge metrics
- PR metrics pending
Description
the parser uses a u16 to track angle brackets. This isn't exactly unreasonable, but not everyone writes reasonable code. Some people don't, and this makes the compiler sad. It should probably be a u32.
I expected to see this happen: no integer overflow
Instead, this happened: integer overflow
Meta
rustc --version --verbose:
roughly rustc 1.77.0-nightly (3cdd004e5 2023-12-29)
Backtrace
[INFO] [stderr] thread 'rustc' panicked at compiler/rustc_parse/src/parser/mod.rs:740:13:
[INFO] [stderr] attempt to add with overflow
[INFO] [stderr] stack backtrace:
[INFO] [stderr] 0: 0x7fc9fab8b946 - std::backtrace_rs::backtrace::libunwind::trace::h5f2f9ef1f20601b2
[INFO] [stderr] at /rustc/fe8f664b41f030f307cfeb6cb8c3a1419292aeed/library/std/src/../../backtrace/src/backtrace/libunwind.rs:104:5
[INFO] [stderr] 1: 0x7fc9fab8b946 - std::backtrace_rs::backtrace::trace_unsynchronized::h0afa123c60ac3544
[INFO] [stderr] at /rustc/fe8f664b41f030f307cfeb6cb8c3a1419292aeed/library/std/src/../../backtrace/src/backtrace/mod.rs:66:5
[INFO] [stderr] 2: 0x7fc9fab8b946 - std::sys_common::backtrace::_print_fmt::h6bf637b081885c8e
[INFO] [stderr] at /rustc/fe8f664b41f030f307cfeb6cb8c3a1419292aeed/library/std/src/sys_common/backtrace.rs:68:5
[INFO] [stderr] 3: 0x7fc9fab8b946 - <std::sys_common::backtrace::_print::DisplayBacktrace as core::fmt::Display>::fmt::h2c6761a2e200c979
[INFO] [stderr] at /rustc/fe8f664b41f030f307cfeb6cb8c3a1419292aeed/library/std/src/sys_common/backtrace.rs:44:22
[INFO] [stderr] 4: 0x7fc9fabde060 - core::fmt::rt::Argument::fmt::h16857210251b8080
[INFO] [stderr] at /rustc/fe8f664b41f030f307cfeb6cb8c3a1419292aeed/library/core/src/fmt/rt.rs:142:9
[INFO] [stderr] 5: 0x7fc9fabde060 - core::fmt::write::h15e31c36c28ee02f
[INFO] [stderr] at /rustc/fe8f664b41f030f307cfeb6cb8c3a1419292aeed/library/core/src/fmt/mod.rs:1120:17
[INFO] [stderr] 6: 0x7fc9fab7f2df - std::io::Write::write_fmt::h30eda9caba94b19c
[INFO] [stderr] at /rustc/fe8f664b41f030f307cfeb6cb8c3a1419292aeed/library/std/src/io/mod.rs:1810:15
[INFO] [stderr] 7: 0x7fc9fab8b724 - std::sys_common::backtrace::_print::h83083a5d53637ec4
[INFO] [stderr] at /rustc/fe8f664b41f030f307cfeb6cb8c3a1419292aeed/library/std/src/sys_common/backtrace.rs:47:5
[INFO] [stderr] 8: 0x7fc9fab8b724 - std::sys_common::backtrace::print::hc98591726bef92fd
[INFO] [stderr] at /rustc/fe8f664b41f030f307cfeb6cb8c3a1419292aeed/library/std/src/sys_common/backtrace.rs:34:9
[INFO] [stderr] 9: 0x7fc9fab8e4b7 - std::panicking::default_hook::{{closure}}::hc8badbdd77cc4572
[INFO] [stderr] 10: 0x7fc9fab8e219 - std::panicking::default_hook::ha24461576e8ae120
[INFO] [stderr] at /rustc/fe8f664b41f030f307cfeb6cb8c3a1419292aeed/library/std/src/panicking.rs:292:9
[INFO] [stderr] 11: 0x7fc9fdaa28ac - std[9f4ae9e9cff43acb]::panicking::update_hook::<alloc[acd61960e0df7531]::boxed::Box<rustc_driver_impl[d22198136dec6837]::install_ice_hook::{closure#0}>>::{closure#0}
[INFO] [stderr] 12: 0x7fc9fab8ec06 - <alloc::boxed::Box<F,A> as core::ops::function::Fn<Args>>::call::h55151e58e7322d9e
[INFO] [stderr] at /rustc/fe8f664b41f030f307cfeb6cb8c3a1419292aeed/library/alloc/src/boxed.rs:2029:9
[INFO] [stderr] 13: 0x7fc9fab8ec06 - std::panicking::rust_panic_with_hook::hed55d523c6a2382e
[INFO] [stderr] at /rustc/fe8f664b41f030f307cfeb6cb8c3a1419292aeed/library/std/src/panicking.rs:783:13
[INFO] [stderr] 14: 0x7fc9fab8e919 - std::panicking::begin_panic_handler::{{closure}}::h944452fa41308f37
[INFO] [stderr] at /rustc/fe8f664b41f030f307cfeb6cb8c3a1419292aeed/library/std/src/panicking.rs:649:13
[INFO] [stderr] 15: 0x7fc9fab8be46 - std::sys_common::backtrace::__rust_end_short_backtrace::h91d397e41fb21da0
[INFO] [stderr] at /rustc/fe8f664b41f030f307cfeb6cb8c3a1419292aeed/library/std/src/sys_common/backtrace.rs:171:18
[INFO] [stderr] 16: 0x7fc9fab8e6b0 - rust_begin_unwind
[INFO] [stderr] at /rustc/fe8f664b41f030f307cfeb6cb8c3a1419292aeed/library/std/src/panicking.rs:645:5
[INFO] [stderr] 17: 0x7fc9fabda765 - core::panicking::panic_fmt::he0a5a6033f24be27
[INFO] [stderr] at /rustc/fe8f664b41f030f307cfeb6cb8c3a1419292aeed/library/core/src/panicking.rs:72:14
[INFO] [stderr] 18: 0x7fc9fabda823 - core::panicking::panic::hc85da36c3a268157
[INFO] [stderr] at /rustc/fe8f664b41f030f307cfeb6cb8c3a1419292aeed/library/core/src/panicking.rs:144:5
[INFO] [stderr] 19: 0x7fc9ff34c9ac - <rustc_parse[951bc98562c6db9b]::parser::Parser>::eat_lt
[INFO] [stderr] 20: 0x7fc9ff25d7c5 - <rustc_parse[951bc98562c6db9b]::parser::Parser>::parse_path_inner
[INFO] [stderr] 21: 0x7fc9ff4c65c2 - <rustc_parse[951bc98562c6db9b]::parser::Parser>::parse_ty_common
[INFO] [stderr] 22: 0x7fc9ff351a03 - <rustc_parse[951bc98562c6db9b]::parser::Parser>::parse_angle_args
[INFO] [stderr] 23: 0x7fc9ff25d81e - <rustc_parse[951bc98562c6db9b]::parser::Parser>::parse_path_inner
<snip snip snip>
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Read compiler/rustc_parse/src/parser/mod.rs around line 740 and follow the Parser::eat_lt path shown in the backtrace. Reproduce the dialectic-macro case from the linked revision, then verify that deeply nested angle brackets no longer trigger integer overflow. Done means the parser handles that input without overflowing.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- rust
- Domain
- compilers
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 45/100