Detect overlong patterns earlier.

This commit is contained in:
Philip.Hazel 2017-01-03 11:35:26 +00:00
parent 84601d910b
commit 15c30bf55a
2 changed files with 11 additions and 2 deletions

View File

@ -306,6 +306,9 @@ In addition, colour settings containing anything other than digits and
semicolon are ignored, and the colour controls are no longer output for empty
strings.
47. Detecting patterns that are too large inside the length-measuring loop
saves processing ridiculously long patterns to their end.
Version 10.22 29-July-2016
--------------------------

View File

@ -4659,7 +4659,7 @@ for (;; pptr++)
meta = META_CODE(*pptr);
meta_arg = META_DATA(*pptr);
/* If we are in the pre-compile phase, accumulate the length used for the
previous cycle of this loop, unless the next item is a quantifier. */
@ -4693,6 +4693,11 @@ for (;; pptr++)
return 0;
}
*lengthptr += (PCRE2_SIZE)(code - orig_code);
if (*lengthptr > MAX_PATTERN_SIZE)
{
*errorcodeptr = ERR20; /* Pattern is too large */
return 0;
}
code = orig_code;
}
@ -7334,7 +7339,6 @@ for (;;)
}
*lengthptr += length;
}
// if (lengthptr == NULL) fprintf(stderr, "~~group returns %d\n", okreturn);
return okreturn;
}
@ -9075,6 +9079,8 @@ code = cworkspace;
if (errorcode != 0) goto HAD_CB_ERROR; /* Offset is in cb.erroroffset */
/* This should be caught in compile_regex(), but just in case... */
if (length > MAX_PATTERN_SIZE)
{
errorcode = ERR20;