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-22581 Fix RBBI Leakage #2731

Merged
merged 1 commit into from
Dec 8, 2023
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
8 changes: 8 additions & 0 deletions icu4c/source/common/rbbiscan.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -289,6 +289,9 @@ UBool RBBIRuleScanner::doParseActions(int32_t action)

// Terminate expression, leaves expression parse tree rooted in TOS node.
fixOpStack(RBBINode::precStart);
if (U_FAILURE(*fRB->fStatus)) {
break;
}

RBBINode *startExprNode = fNodeStack[fNodeStackPtr-2];
RBBINode *varRefNode = fNodeStack[fNodeStackPtr-1];
Expand All @@ -312,6 +315,11 @@ UBool RBBIRuleScanner::doParseActions(int32_t action)
UErrorCode t = *fRB->fStatus;
*fRB->fStatus = U_ZERO_ERROR;
error(t);
// When adding $variableRef to the symbol table fail, Delete
// both nodes because deleting varRefNode will not delete
// RHSExprNode internally.
delete RHSExprNode;
delete varRefNode;
}

// Clean up the stack.
Expand Down
9 changes: 9 additions & 0 deletions icu4c/source/test/intltest/rbbitst.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,7 @@ void RBBITest::runIndexedTest( int32_t index, UBool exec, const char* &name, cha
TESTCASE_AUTO(TestRandomAccess);
TESTCASE_AUTO(TestExternalBreakEngineWithFakeTaiLe);
TESTCASE_AUTO(TestExternalBreakEngineWithFakeYue);
TESTCASE_AUTO(TestBug22581);
TESTCASE_AUTO(TestBug22584);

#if U_ENABLE_TRACING
Expand Down Expand Up @@ -5873,4 +5874,12 @@ void RBBITest::TestBug22584() {
RuleBasedBreakIterator bi(ruleStr, pe, ec);
}

void RBBITest::TestBug22581() {
// Test duplicate variable setting will not leak the rule compilation
UnicodeString ruleStr = u"$foo=[abc]; $foo=[xyz]; $foo;";
UParseError pe {};
UErrorCode ec {U_ZERO_ERROR};

RuleBasedBreakIterator bi(ruleStr, pe, ec);
}
#endif // #if !UCONFIG_NO_BREAK_ITERATION
1 change: 1 addition & 0 deletions icu4c/source/test/intltest/rbbitst.h
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@ class RBBITest: public IntlTest {
void TestRandomAccess();
void TestExternalBreakEngineWithFakeTaiLe();
void TestExternalBreakEngineWithFakeYue();
void TestBug22581();
void TestBug22584();

#if U_ENABLE_TRACING
Expand Down
Loading