Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ICU-21492 Fix regex compile assertion failure. #1577

Merged
merged 1 commit into from
Feb 18, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions icu4c/source/i18n/regexcmp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3475,6 +3475,9 @@ int32_t RegexCompile::minMatchLength(int32_t start, int32_t end) {
// value may be longer than the actual maximum; it must
// never be shorter.
//
// start, end: the range of the pattern to check.
// end is inclusive.
//
//------------------------------------------------------------------------------
int32_t RegexCompile::maxMatchLength(int32_t start, int32_t end) {
if (U_FAILURE(*fStatus)) {
Expand Down Expand Up @@ -3720,14 +3723,14 @@ int32_t RegexCompile::maxMatchLength(int32_t start, int32_t end) {
// Look-behind. Scan forward until the matching look-around end,
// without processing the look-behind block.
int32_t dataLoc = URX_VAL(op);
for (loc = loc + 1; loc < end; ++loc) {
for (loc = loc + 1; loc <= end; ++loc) {
op = (int32_t)fRXPat->fCompiledPat->elementAti(loc);
int32_t opType = URX_TYPE(op);
if ((opType == URX_LA_END || opType == URX_LBN_END) && (URX_VAL(op) == dataLoc)) {
break;
}
}
U_ASSERT(loc < end);
U_ASSERT(loc <= end);
}
break;

Expand Down
5 changes: 5 additions & 0 deletions icu4c/source/test/testdata/regextst.txt
Original file line number Diff line number Diff line change
Expand Up @@ -1497,6 +1497,11 @@
#
"(?w)\b" v2 "äää<0></0> äää"

# Bug ICU-21492 Assertion failure with nested look-around expressions.
#
"(?<=(?:(?<=(?:(?<=(?:(?<=)){2})){3})){4}" E "<0></0>" # orig failure from bug report, w mismatched parens.
"(?:(?<=(?:(?<=)){2}))" "<0></0>" # Simplified case, with a valid pattern.

# Random debugging, Temporary
#

Expand Down