Skip to content

expr: deeply nested parentheses cause a stack overflow (recursive parser) #13146

Closed

Description

@sylvestre

Reported by @HackingRepo via security advisory GHSA-gr9g-xjfw-pqfw. We don't consider this a security issue, so we're tracking it as a regular bug.

Description
expr uses a recursive-descent parser with no depth limit, so a deeply nested expression aborts the process with a stack overflow instead of evaluating or erroring cleanly.

Repro

$ expr $(python3 -c "print('('*5000)") 1 $(python3 -c "print(')'*5000)")
thread 'main' has overflowed its stack
fatal runtime error: stack overflow, aborting   # SIGABRT

GNU evaluates the same input and exits 0.

Expected: bounded recursion (or iterative parsing) returning a normal result/error.
Actual: stack overflow → abort. A crash on untrusted input.

Activity

  1. sylvestre commented on Jun 28, 2026

    @sylvestre
    SponsorContributorAuthor

    i am sorry, i didn't realized that you reported them

  2. HackingRepo commented on Jun 28, 2026

    @HackingRepo
    Contributor

    ok but no issue, let's track that one better, since that one closed as duplicate, no worry

  3. added a commit that references this issue on Jul 16, 2026
    d227a51
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

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions