mirror of
https://github.com/openjdk/jdk.git
synced 2025-08-27 14:54:52 +02:00
8224789: Parsing repetition count in regex does not detect numeric overflow
Reviewed-by: rriggs, bchristi
This commit is contained in:
parent
051b4e2963
commit
f5e2916507
2 changed files with 70 additions and 24 deletions
|
@ -3271,28 +3271,33 @@ loop: for(int x=0, offset=0; x<nCodePoints; x++, offset+=len) {
|
|||
case '+':
|
||||
return curly(prev, 1);
|
||||
case '{':
|
||||
ch = temp[cursor+1];
|
||||
ch = skip();
|
||||
if (ASCII.isDigit(ch)) {
|
||||
skip();
|
||||
int cmin = 0;
|
||||
do {
|
||||
cmin = cmin * 10 + (ch - '0');
|
||||
} while (ASCII.isDigit(ch = read()));
|
||||
int cmax = cmin;
|
||||
if (ch == ',') {
|
||||
ch = read();
|
||||
cmax = MAX_REPS;
|
||||
if (ch != '}') {
|
||||
cmax = 0;
|
||||
while (ASCII.isDigit(ch)) {
|
||||
cmax = cmax * 10 + (ch - '0');
|
||||
ch = read();
|
||||
int cmin = 0, cmax;
|
||||
try {
|
||||
do {
|
||||
cmin = Math.addExact(Math.multiplyExact(cmin, 10),
|
||||
ch - '0');
|
||||
} while (ASCII.isDigit(ch = read()));
|
||||
cmax = cmin;
|
||||
if (ch == ',') {
|
||||
ch = read();
|
||||
cmax = MAX_REPS;
|
||||
if (ch != '}') {
|
||||
cmax = 0;
|
||||
while (ASCII.isDigit(ch)) {
|
||||
cmax = Math.addExact(Math.multiplyExact(cmax, 10),
|
||||
ch - '0');
|
||||
ch = read();
|
||||
}
|
||||
}
|
||||
}
|
||||
} catch (ArithmeticException ae) {
|
||||
throw error("Illegal repetition range");
|
||||
}
|
||||
if (ch != '}')
|
||||
throw error("Unclosed counted closure");
|
||||
if (((cmin) | (cmax) | (cmax - cmin)) < 0)
|
||||
if (cmax < cmin)
|
||||
throw error("Illegal repetition range");
|
||||
Curly curly;
|
||||
ch = peek();
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue