Skip to content

Commit 32973fa

Browse files
committed
fix(regex): a repeat count over RE_DUP_MAX is "Invalid content of \{\}"
A `\{n\}` / `\{n,m\}` count exceeding RE_DUP_MAX (0xffff) reached the interval compiler and failed the i16 counter conversion with "Regular expression too big". GNU rejects it earlier, while reading the number (GET_UNSIGNED_NUMBER in regex-emacs.c), with `(invalid-regexp "Invalid content of \{\}")`. Add the RE_DUP_MAX bound check right after parsing the bounds so an over-large count signals the same error as GNU. Fixes div_r5_regex_repeat_interval_edge_validation. (Counts in 32768..=65535, which GNU compiles but neomacs's i16 counters still reject, remain a separate counter-width follow-up: div_r6.)
1 parent bd3ddd5 commit 32973fa

1 file changed

Lines changed: 10 additions & 0 deletions

File tree

neovm-core/src/emacs_core/regex_emacs.rs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2295,6 +2295,16 @@ fn parse_interval(
22952295
Some(min) // \{n\} — exact count
22962296
};
22972297

2298+
// GNU's GET_UNSIGNED_NUMBER (regex-emacs.c) rejects a repeat count that
2299+
// exceeds RE_DUP_MAX (0xffff) with `(invalid-regexp "Invalid content of
2300+
// \\{\\}")` while reading the number -- not the generic "too big".
2301+
const RE_DUP_MAX: usize = 0xffff;
2302+
if min > RE_DUP_MAX || max.is_some_and(|m| m > RE_DUP_MAX) {
2303+
return Err(RegexCompileError {
2304+
message: "Invalid content of \\{\\}".to_string(),
2305+
});
2306+
}
2307+
22982308
// GNU regex-emacs.c:2390 rejects a descending interval where a finite
22992309
// upper bound is smaller than the lower bound (e.g. `a\{2,1\}`), signaling
23002310
// `(invalid-regexp "Invalid content of \\{\\}")`. An unbounded `\{n,\}`

0 commit comments

Comments
 (0)