Skip to content

Commit

Permalink
ICU-22504 Fix buffer overflow write error
Browse files Browse the repository at this point in the history
  • Loading branch information
FrankYFTang committed Sep 15, 2023
1 parent 832997c commit 386e9a1
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 2 deletions.
13 changes: 11 additions & 2 deletions icu4c/source/common/uloc_tag.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1326,14 +1326,23 @@ _appendKeywordsToLanguageTag(const char* localeID, icu::ByteSink& sink, UBool st
attrBufLength = 0;
for (; i < len; i++) {
if (buf[i] != '-') {
attrBuf[attrBufLength++] = buf[i];
if (static_cast<size_t>(attrBufLength) < sizeof(attrBuf)) {
attrBuf[attrBufLength++] = buf[i];
} else {
*status = U_ILLEGAL_ARGUMENT_ERROR;
return;
}
} else {
i++;
break;
}
}
if (attrBufLength > 0) {
attrBuf[attrBufLength] = 0;
if (static_cast<size_t>(attrBufLength) < sizeof(attrBuf)) {
attrBuf[attrBufLength] = 0;
} else {
*status = U_STRING_NOT_TERMINATED_WARNING;
}

} else if (i >= len){
break;
Expand Down
2 changes: 2 additions & 0 deletions icu4c/source/test/intltest/loctest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5982,6 +5982,8 @@ void LocaleTest::TestToLanguageTag() {
{"und-1994-biske-rozaj-x-private", "und-1994-biske-rozaj-x-private"},
// ICU-22497
{"-ins0-ins17Rz-yqyq-UWLF-uRyq-UWLF-uRRyq-UWLF-uR-UWLF-uRns0-ins17Rz-yq-UWLF-uRyq-UWLF-uRRyq-LF-uRyq-UWLF-uRRyq-UWLF-uRq-UWLF-uRyq-UWLF-uRRyq-UWLF-uR", ""},
// ICU-22504
{"@attribute=zzo9zzzzzzzs0zzzzzzzzzz55555555555555555555500000000000000000000fffffffffffffffffffffffffzzzzz2mfPAK", ""},
};
int32_t i;
for (i=0; i < UPRV_LENGTHOF(testCases); i++) {
Expand Down

1 comment on commit 386e9a1

@github-actions
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Performance Alert ⚠️

Possible performance regression was detected for benchmark.
Benchmark result of this commit is worse than the previous benchmark result exceeding threshold 2.

Benchmark suite Current: 386e9a1 Previous: 832997c Ratio
TestCharsetEncoderICU 10.236316176690066 ns/iter 4.06099797975717 ns/iter 2.52

This comment was automatically generated by workflow using github-action-benchmark.

Please sign in to comment.