Skip to content

Parsing repeated ( / opened subexpressions goes OOM #16186

@sholderbach

Description

@sholderbach

Describe the bug

Parsing repeated open parens causes nu to consume many GBs of memory and crashing.

Found while trying to fuzz nu-parser's parse_with_keywords target.

This behavior sounds similar to #15241 in conceptual terms (i.e. many unclosed nested AST structures) but is different in manifestation that it does not fail with a stack overflow but a general memory leak.

More closely related in behavior to #13944

How to reproduce

use ulimit -m before launching the nu under test, to limit the consumed memory.
Type ((((((((((((((((((( into the repl (or a few more or less ( depending on the available memory)
Syntax highlighting stalls and the process gets killed.

Saving the same sequence to a script test.nu and running nu test.nu does not trigger for the same number of open ( and instead reports back with the error:

Error: nu::parser::unexpected_eof

  × Unexpected end of code.
   ╭─[/home/stefan/nushell/crates/nu-parser/fuzz/testrepr.nu:1:20]
 1 │ (((((((((((((((((((
   ·                    ┬
   ·                    ╰── expected closing )
   ╰────

Expected behavior

No memory leak, no stack overflow, just appropriate parse errors

Configuration

key value
version 0.105.1
major 0
minor 105
patch 1
branch
commit_hash
build_os linux-x86_64
build_target x86_64-unknown-linux-gnu
rust_version rustc 1.88.0 (6b00bc388 2025-06-23)
rust_channel stable-x86_64-unknown-linux-gnu
cargo_version cargo 1.88.0 (873a06493 2025-05-10)
build_time 2025-07-06 20:25:09 +02:00
build_rust_channel release
allocator standard
features default, sqlite, trash
installed_plugins plotters 0.1.7+0.105.1

Metadata

Metadata

Assignees

Labels

A:parserIssues related to parsingcategory:bugSomething isn't workingpanicperformanceWork to make nushell quicker and use less resources

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions