Skip to content
Tcl Source Code Ticket Change Details
Login

Ticket Change Details

Overview

Artifact ID: 7d77e4c29a9a27ff66b34bc1a320227250a9b1389426d32181e5027c18edc67d
Ticket: 41bc9a82988d930fc00145bcd02bb3ce4e169a2c
regsub -command panics with more than 9 capturing groups
User & Date: serhiy.storchaka on 2026-10-11 06:54:45
Changes

  1. cmimetype changed to: "text/x-fossil-wiki"
  2. comment changed to:
    <tt>regsub -command</tt> with more than 9 capturing groups can panic:
    <verbatim>
    set re {(a)(b)(c)(d)(e)(f)(g)(h)(i)(j)(k)(l)}
    regsub -command $re abcdefghijkl {apply {args {list [llength $args] $args}}}
    </verbatim>
    In 9.0.5 this panics with "unable to alloc 643662021519030588 bytes". In 9.1.1 it happens not to crash, but the last three arguments are empty instead of <tt>j k l</tt>. Valgrind reports uninitialised reads in <tt>Tcl_RegsubObjCmd()</tt> in both.
    
    <tt>Tcl_RegsubObjCmd()</tt> always asks the regexp engine for 10 submatches, but with <tt>-command</tt> it passes all <tt>info.nsubs</tt> + 1 of them to the command, reading entries of the match array that were never set, and uses them as string positions and lengths. Asking for all submatches when <tt>-command</tt> is used fixes it; regsub.n also says that each substring matching a capturing sub-RE is appended.
    
  3. foundin changed to: "9.0.5, 9.1.0"
  4. login: "serhiy.storchaka"
  5. priority changed to: "5 Medium"
  6. resolution changed to: "None"
  7. severity changed to: "Severe"
  8. status changed to: "Open"
  9. submitter changed to: "serhiy.storchaka"
  10. subsystem changed to: "43. Regexp"
  11. title changed to:
    regsub -command panics with more than 9 capturing groups
    
  12. type changed to: "Bug"