Skip to content
Tcl Source Code Ticket Change Details
Login

Ticket Change Details

Overview

Artifact ID: a1745c694ba9a744a12902045b8de9247d7131d2df15e69b450fe3c146c4bffd
Ticket: 7d47ba7d9497fda88c064b6152d3a2126c3cd9d2
Stack overruns in regexp code
User & Date: serhiy.storchaka on 2026-10-10 20:48:01
Changes

  1. foundin changed to: "8.6.18, 9.0.5, 9.1.0"
  2. icomment:
    The <tt>(^$)+</tt> example is long fixed, but stack overflow was still easy to trigger in 8.6, 9.0 and 9.1: parentheses nested 40000 deep crashed in <tt>parse()</tt>, and lookahead constraints nested only 600 deep crashed in the <tt>checkLAConstraint()</tt> recursion, because each level kept a 16 KB small DFA on the stack. <tt>STACK_TOO_DEEP()</tt> was still defined as 0.
    
    Proposed fix in branch [/timeline?r=regexp-stack-depth|regexp-stack-depth], following your proposal: <tt>STACK_TOO_DEEP()</tt> limits the stack used by one compile or execution to <tt>REG_MAX_STACK_DEPTH</tt> (1 MB by default), measured from a local variable of <tt>compile()</tt> or <tt>exec()</tt>, and it is checked in the same places as in PostgreSQL. Lookahead DFAs are cached per execution, as in PostgreSQL's <tt>getladfa()</tt>, instead of being built on the stack. Too deep nesting now fails with "regular expression is too complex". Tests reg-33.32 to 33.35.
    
  3. login: "serhiy.storchaka"
  4. mimetype: "text/x-fossil-wiki"