Skip to content

Commit 669751d

Browse files
authored
Vulnerability: Memory Corruption in libphonenumber AsYouTypeFormatter::AttemptToExtractIdd (#3924)
1 parent ebd99c8 commit 669751d

File tree

2 files changed

+17
-1
lines changed

2 files changed

+17
-1
lines changed

cpp/src/phonenumbers/asyoutypeformatter.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -712,9 +712,9 @@ char AsYouTypeFormatter::NormalizeAndAccrueDigitsAndPlusSign(
712712
string number;
713713
UnicodeString(next_char).toUTF8String(number);
714714
phone_util_.NormalizeDigitsOnly(&number);
715-
accrued_input_without_formatting_.append(next_char);
716715
national_number_.append(number);
717716
normalized_char = number[0];
717+
accrued_input_without_formatting_.append(normalized_char);
718718
}
719719
if (remember_position) {
720720
position_to_remember_ = accrued_input_without_formatting_.length();

cpp/test/phonenumbers/asyoutypeformatter_test.cc

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -916,6 +916,22 @@ TEST_F(AsYouTypeFormatterTest, AYTF_LongIDD_AU) {
916916
EXPECT_EQ("0011 244 250 253 222", formatter_->InputDigit('2', &result_));
917917
}
918918

919+
TEST_F(AsYouTypeFormatterTest, AYTF_With_Special_Characters) {
920+
formatter_.reset(phone_util_.GetAsYouTypeFormatter(RegionCode::JP()));
921+
// +81००23456
922+
formatter_->Clear();
923+
EXPECT_EQ("+", formatter_->InputDigit('+', &result_));
924+
EXPECT_EQ("+8", formatter_->InputDigit('8', &result_));
925+
EXPECT_EQ("+81 ", formatter_->InputDigit('1', &result_));
926+
EXPECT_EQ("+81 0", formatter_->InputDigit(UnicodeString("\u0966")[0], &result_));
927+
EXPECT_EQ("+81 00", formatter_->InputDigit(UnicodeString("\u0966")[0], &result_));
928+
EXPECT_EQ("+81००2", formatter_->InputDigit('2', &result_));
929+
EXPECT_EQ("+81००23", formatter_->InputDigit('3', &result_));
930+
EXPECT_EQ("+81००234", formatter_->InputDigit('4', &result_));
931+
EXPECT_EQ("+81००2345", formatter_->InputDigit('5', &result_));
932+
EXPECT_EQ("+81००23456", formatter_->InputDigit('6', &result_));
933+
}
934+
919935
TEST_F(AsYouTypeFormatterTest, AYTF_LongIDD_KR) {
920936
formatter_.reset(phone_util_.GetAsYouTypeFormatter(RegionCode::KR()));
921937
// 00300 1 650 253 2250

0 commit comments

Comments
 (0)