RegExp: patterns with more than 255 capture groups fail with "too many captures"
I maintainer di solito rispondono entro 5 giorni
Valutazione
- Difficoltà
- 4/5
- Tempo stimato
- 3-5 giorni
- Idoneità per principianti
- 25/100
- Tipo di issue
- Bug
- Chiarezza
- Specificata chiaramente
- Stato di attività
- Ferma
- Stack tecnologico
- c, javascript
- Ambito
- compilers
Direzione di ricerca
Start in libregexp.c at CAPTURE_COUNT_MAX and the opcodes save_start, save_end, save_reset and the back-reference ops, plus the RE_HEADER_CAPTURE_COUNT header field. Widening the capture index to 16 bits touches the bytecode format, so check every reader and writer. Done when the 300-group repro in the issue compiles and back-references to groups past 255 still match. Pull request #625 already covers this, so coordinate there first.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Descrizione
libregexp.c limits a regular expression to 255 capture groups (CAPTURE_COUNT_MAX 255); a pattern with more fails to compile with SyntaxError: too many captures. ECMAScript sets no such limit, and V8, SpiderMonkey and JavaScriptCore accept patterns with thousands of groups.
Reproduction
let src = "";
for (let i = 0; i < 300; i++) src += "(a)?";
new RegExp(src); // SyntaxError: too many captures
Where it shows up
This is not only a synthetic case. Bundlers generate such patterns: rspack's CSS chunk loader tests chunk ids with one large alternation in which every branch is a capture group, e.g.
/^(4(0(1(071|295|317|425)|074|271|3655|...)|...)|...)$/.test(chunkId)
A large web application (Discord's web client) ships an entry bundle with more than 255 groups in that test, so the whole bundle fails to parse and the application never starts.
Cause
The capture index is a single byte throughout: the operand of save_start/save_end, both operands of save_reset, the back-reference count and indices, and the capture count in the bytecode header (RE_HEADER_CAPTURE_COUNT).
Possible fix
Widening these to 16 bits removes the limit in practice (65535 groups) without changing the matcher: save_start/save_end take a u16 operand, save_reset two, back-references a u16 count followed by u16 indices, and the header stores the capture count as a u16 (the header grows from 8 to 10 bytes). Capture storage is already heap-allocated by the callers from lre_get_alloc_count(), so a larger count only costs memory for patterns that actually use it. We made this change in a downstream fork and it passes the regexp tests we run, plus back-references and named back-references to groups past 255.
- Lingua principale
- C
- Stelle
- 11.1k
- Fork
- 1.2k
- Metriche di merge delle PR
- Nessuna PR unita negli ultimi 30g
Preparare l'ambiente
Questo progetto non fornisce container di sviluppo, Dockerfile né guida per i contributori, quindi l'ambiente è a tuo carico: parti dal suo README e consulta la nostra guida al primo contributo per i passaggi generali.
Come iniziare
- Leggi tutta la issue e poi la guida ai contributi del progetto.
- Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
- Fai un fork del repository e lavora su un branch.
- Apri una pull request che faccia riferimento al numero della issue.
Altre issue di bellard/quickjs
-
Difficoltà 1/5 Meno di un'ora Idoneità per principianti 75/100
I maintainer di solito rispondono entro 5 giorni
-
Difficoltà 4/5 3-5 giorni Idoneità per principianti 48/100
bellard/quickjs#620 · 1 commento ·
I maintainer di solito rispondono entro 5 giorni
-
(comment on #611) `function g(a, d = (a = 10)) { return a; }` returns the argument instead of 10Aperta
Difficoltà 4/5 3-5 giorni Idoneità per principianti 30/100
I maintainer di solito rispondono entro 5 giorni
-
Account for Map/Set retained strings in JS_ComputeMemoryUsage, or document partial accountingAperta
Difficoltà 4/5 3-5 giorni Idoneità per principianti 30/100
I maintainer di solito rispondono entro 5 giorni
-
`{ ..."ab" }` is `{}`; a throw in a `for await` body does not wait for the iterator's return()Aperta
Difficoltà 5/5 Più di una settimana Idoneità per principianti 35/100
bellard/quickjs#611 · 1 commento ·
I maintainer di solito rispondono entro 5 giorni
Tutte le issue di bellard/quickjs
Issue simili
-
Fix a typo in H5Centry.cAperta
Difficoltà 1/5 Meno di un'ora Idoneità per principianti 85/100
I maintainer di solito rispondono entro 1 giorno
-
Difficoltà 1/5 Meno di un'ora Idoneità per principianti 88/100
FujiNetWIFI/fujinet-firmware#2518 ·
I maintainer di solito rispondono entro 1 giorno
-
[mimalloc] update to 3.7.1Apertacategory:port-update
Difficoltà 2/5 1-3 ore Idoneità per principianti 65/100
I maintainer di solito rispondono entro 2 giorni
-
enhancement
Difficoltà 2/5 1-3 ore Idoneità per principianti 72/100
lauppv/cyberstars#610 ·
I maintainer di solito rispondono entro 1 giorno
-
documentation good first issue help wanted
Difficoltà 2/5 1-3 ore Idoneità per principianti 72/100