Permalink
Browse files

Merge change 23409 into donut

* changes:
  Avoid a buffer overrun in GET_NORMALIZED_STRING.
  • Loading branch information...
2 parents 0d04c4c + cc6719f commit 07a39f12058ddbc9bcf9200e4d5883e4f4b6fd95 Android (Google) Code Review committed Sep 1, 2009
Showing with 14 additions and 3 deletions.
  1. +3 −3 android/PhoneticStringUtils.cpp
  2. +11 −0 android/PhoneticStringUtilsTest.cpp
@@ -292,23 +292,23 @@ static bool GetExpectedString(
src = STR_FOR_NULL_STR;
}
- char32_t codepoints[MAX_CODEPOINTS];
+ char32_t codepoints[MAX_CODEPOINTS]; // if array size is changed the for loop needs to be changed
size_t src_len = utf8_length(src);
if (src_len == 0) {
return false;
}
bool next_is_consumed;
size_t j = 0;
- for (size_t i = 0; i < src_len;) {
+ for (size_t i = 0; i < src_len && j < MAX_CODEPOINTS;) {
int32_t ret = utf32_at(src, src_len, i, &i);
if (ret < 0) {
// failed to parse UTF-8
return false;
}
ret = get_codepoint_function(
static_cast<char32_t>(ret),
- i + 1 < src_len ? codepoints[i + 1] : 0,
+ i + 1 < src_len ? src[i + 1] : 0,
&next_is_consumed);
if (ret > 0) {
codepoints[j] = static_cast<char32_t>(ret);
@@ -39,6 +39,7 @@ class TestExecutor {
void testGetUtf8FromUtf32();
void testGetPhoneticallySortableString();
void testGetNormalizedString();
+ void testLongString();
// Note: When adding a test, do not forget to add it to DoOneTest().
@@ -75,6 +76,7 @@ bool TestExecutor::DoAllTests() {
DoOneTest(&TestExecutor::testGetUtf8FromUtf32);
DoOneTest(&TestExecutor::testGetPhoneticallySortableString);
DoOneTest(&TestExecutor::testGetNormalizedString);
+ DoOneTest(&TestExecutor::testLongString);
printf("Test total: %d\nSuccess: %d\nFailure: %d\n",
m_total_count, m_success_count, m_total_count - m_success_count);
@@ -415,6 +417,15 @@ void TestExecutor::testGetNormalizedString() {
EXPECT_EQ_UTF8_UTF8(" \t", " \t");
}
+void TestExecutor::testLongString() {
+ printf("testLongString()\n");
+ char * dst;
+ size_t len;
+ EXPECT_EQ_UTF8_UTF8("Qqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqtttttttttttttttttttttttttttttttttttttttttttttttttgggggggggggggggggggggggggggggggggggggggbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb",
+ "Qqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqtttttttttttttttttttttttttttttttttttttttttttttttttggggggggggggggggggggggggggggggggggg");
+}
+
+
int main() {
TestExecutor executor;
if(executor.DoAllTests()) {

0 comments on commit 07a39f1

Please sign in to comment.