Skip to content
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
23 changes: 20 additions & 3 deletions icu4c/source/common/putil.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -915,8 +915,15 @@ static UBool compareBinaryFiles(const char* defaultTZFileName, const char* TZFil
fseek(tzInfo->defaultTZFilePtr, 0, SEEK_END);
tzInfo->defaultTZFileSize = ftell(tzInfo->defaultTZFilePtr);
}
fseek(file, 0, SEEK_END);
if (fseek(file, 0, SEEK_END) != 0) {
fclose(file);
return false;
}
sizeFile = ftell(file);
if (sizeFile == -1) {
fclose(file);
return false;
}
sizeFileLeft = sizeFile;

if (sizeFile != tzInfo->defaultTZFileSize) {
Expand All @@ -926,16 +933,26 @@ static UBool compareBinaryFiles(const char* defaultTZFileName, const char* TZFil
* compare each byte to determine equality.
*/
if (tzInfo->defaultTZBuffer == nullptr) {
rewind(tzInfo->defaultTZFilePtr);
if (fseek(tzInfo->defaultTZFilePtr, 0, SEEK_SET) != 0) {
fclose(file);
return false;
}
tzInfo->defaultTZBuffer = static_cast<char*>(uprv_malloc(sizeof(char) * tzInfo->defaultTZFileSize));
sizeFileRead = fread(tzInfo->defaultTZBuffer, 1, tzInfo->defaultTZFileSize, tzInfo->defaultTZFilePtr);
}
rewind(file);
if (fseek(file, 0, SEEK_SET) != 0) {
fclose(file);
return false;
}
while(sizeFileLeft > 0) {
uprv_memset(bufferFile, 0, MAX_READ_SIZE);
sizeFileToRead = sizeFileLeft < MAX_READ_SIZE ? sizeFileLeft : MAX_READ_SIZE;

sizeFileRead = fread(bufferFile, 1, sizeFileToRead, file);
if (sizeFileRead == -1) {
fclose(file);
return false;
}
if (memcmp(tzInfo->defaultTZBuffer + tzInfo->defaultTZPosition, bufferFile, sizeFileRead) != 0) {
result = false;
break;
Expand Down
8 changes: 8 additions & 0 deletions icu4c/source/common/ucnv.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -877,6 +877,10 @@ _fromUnicodeWithCallback(UConverterFromUnicodeArgs *pArgs, UErrorCode *err) {
* and failed to consume all of them.
* We need to "replay" them from a temporary buffer and convert them first.
*/
if (!pArgs->source) {
*err=U_ILLEGAL_ARGUMENT_ERROR;
return;
}
realSource=pArgs->source;
realSourceLimit=pArgs->sourceLimit;
realFlush=pArgs->flush;
Expand Down Expand Up @@ -1322,6 +1326,10 @@ _toUnicodeWithCallback(UConverterToUnicodeArgs *pArgs, UErrorCode *err) {
* and failed to consume all of them.
* We need to "replay" them from a temporary buffer and convert them first.
*/
if (!pArgs->source) {
*err=U_ILLEGAL_ARGUMENT_ERROR;
return;
}
realSource=pArgs->source;
realSourceLimit=pArgs->sourceLimit;
realFlush=pArgs->flush;
Expand Down
2 changes: 1 addition & 1 deletion icu4c/source/common/udata.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1291,7 +1291,7 @@ doOpenChoice(const char *path, const char *type, const char *name,
dataPath = u_getDataDirectory();

/**** Time zone individual files override */
if (isICUData && isTimeZoneFile(name, type)) {
if (isICUData && type != nullptr && isTimeZoneFile(name, type)) {
const char *tzFilesDir = u_getTimeZoneFilesDirectory(pErrorCode);
if (tzFilesDir[0] != 0) {
#ifdef UDATA_DEBUG
Expand Down
6 changes: 4 additions & 2 deletions icu4c/source/common/uenum.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,8 @@ uenum_unextDefault(UEnumeration* en,
if (ustr == nullptr) {
*status = U_MEMORY_ALLOCATION_ERROR;
} else {
u_charsToUChars(cstr, ustr, len+1);
u_charsToUChars(cstr, ustr, len);
ustr[len] = 0;
}
}
} else {
Expand Down Expand Up @@ -129,7 +130,8 @@ uenum_nextDefault(UEnumeration* en,
*status = U_MEMORY_ALLOCATION_ERROR;
return nullptr;
}
u_UCharsToChars(tempUCharVal, tempCharVal, *resultLength + 1);
u_UCharsToChars(tempUCharVal, tempCharVal, *resultLength);
tempCharVal[*resultLength] = 0;
return tempCharVal;
} else {
*status = U_UNSUPPORTED_ERROR;
Expand Down
1 change: 1 addition & 0 deletions icu4c/source/common/uidna.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -915,6 +915,7 @@ uidna_compare( const char16_t *s1, int32_t length1,

if (U_FAILURE(bufferStatus)) {
*status = bufferStatus;
goto CLEANUP;
}

// when toASCII is applied all label separators are replaced with FULL_STOP
Expand Down
2 changes: 1 addition & 1 deletion icu4c/source/common/uniset.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -241,7 +241,7 @@ UnicodeSet& UnicodeSet::copyFrom(const UnicodeSet& o, UBool asThawed) {
} else if (hasStrings()) {
strings_->removeAllElements();
}
if (o.stringSpan != nullptr && !asThawed) {
if (o.stringSpan != nullptr && strings_ != nullptr && !asThawed) {
stringSpan = new UnicodeSetStringSpan(*o.stringSpan, *strings_);
if (stringSpan == nullptr) { // Check for memory allocation error.
setToBogus();
Expand Down
7 changes: 6 additions & 1 deletion icu4c/source/common/ushape.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -982,7 +982,7 @@ expandCompositCharAtEnd(char16_t *dest, int32_t sourceLength, int32_t destSize,U

uprv_memset(tempbuffer, 0, (sourceLength+1)*U_SIZEOF_UCHAR);

while(dest[inpsize-1] == SPACE_CHAR) {
while(inpsize>0 && dest[inpsize-1] == SPACE_CHAR) {
countr++;
inpsize--;
}
Expand Down Expand Up @@ -1525,6 +1525,11 @@ u_shapeArabic(const char16_t *source, int32_t sourceLength,
prevLink = currLink;
currLink = getLink(source[i]);
if (aggregate_tashkeel && ((prevLink|currLink)&COMBINE) == COMBINE && aggregation_possible) {
if (j<0 || j>=2*sourceLength) {
*pErrorCode=U_ILLEGAL_ARGUMENT_ERROR;
if (tempsource != nullptr) uprv_free(tempsource);
return 0;
}
aggregation_possible = 0;
tempsource[j] = (prev<source[i]?prev:source[i])-0x064C+0xFC5E;
currLink = getLink(tempsource[j]);
Expand Down
4 changes: 3 additions & 1 deletion icu4c/source/i18n/anytrans.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -359,7 +359,9 @@ void AnyTransliterator::registerIDs() {

UErrorCode ec = U_ZERO_ERROR;
Hashtable seen(true, ec);

if (U_FAILURE(ec)) {
return;
}
int32_t sourceCount = Transliterator::_countAvailableSources();
for (int32_t s=0; s<sourceCount; ++s) {
UnicodeString source;
Expand Down
4 changes: 4 additions & 0 deletions icu4c/source/i18n/collationsettings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,10 @@ CollationSettings::setReorderArrays(const int32_t *codes, int32_t codesLength,
int32_t *ownedCodes;
int32_t totalLength = codesLength + rangesLength;
U_ASSERT(totalLength > 0);
if (totalLength <= 0) {
errorCode = U_ILLEGAL_ARGUMENT_ERROR;
return;
}
if(totalLength <= reorderCodesCapacity) {
ownedCodes = const_cast<int32_t *>(reorderCodes);
} else {
Expand Down
3 changes: 3 additions & 0 deletions icu4c/source/i18n/nfrs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -602,6 +602,9 @@ NFRuleSet::findFractionRuleSetRule(double number) const
// all the precision we need, and we can do all of the rest
// of the math using integer arithmetic
int64_t leastCommonMultiple = rules[0]->getBaseValue();
if (leastCommonMultiple == 0) {
return nullptr;
}
int64_t numerator;
{
for (uint32_t i = 1; i < rules.size(); ++i) {
Expand Down
3 changes: 2 additions & 1 deletion icu4c/source/i18n/nfrule.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -903,7 +903,8 @@ NFRule::shouldRollBack(int64_t number) const
// a modulus substitution, its base value isn't an even multiple
// of 100, and the value we're trying to format _is_ an even
// multiple of 100. This is called the "rollback rule."
if ((sub1 != nullptr && sub1->isModulusSubstitution()) || (sub2 != nullptr && sub2->isModulusSubstitution())) {
if (radix != 0 && ((sub1 != nullptr && sub1->isModulusSubstitution()) ||
(sub2 != nullptr && sub2->isModulusSubstitution()))) {
int64_t re = util64_pow(radix, exponent);
return (number % re) == 0 && (baseValue % re) != 0;
}
Expand Down
3 changes: 3 additions & 0 deletions icu4c/source/i18n/number_capi.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -380,6 +380,9 @@ usnumf_formatInt64(
return;
}
auto localResult = formatter->fFormatter.formatInt64(value, *ec);
if (U_FAILURE(*ec)) {
return;
}
result->setTo(std::move(localResult));
}

Expand Down
3 changes: 1 addition & 2 deletions icu4c/source/i18n/scriptset.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -225,9 +225,8 @@ ScriptSet &ScriptSet::parseScripts(const UnicodeString &scriptString, UErrorCode
}
}
if (oneScriptName.length() > 0) {
char buf[40];
char buf[40] = {};
oneScriptName.extract(0, oneScriptName.length(), buf, sizeof(buf)-1, US_INV);
buf[sizeof(buf)-1] = 0;
int32_t sc = u_getPropertyValueEnum(UCHAR_SCRIPT, buf);
if (sc == UCHAR_INVALID_CODE) {
status = U_ILLEGAL_ARGUMENT_ERROR;
Expand Down
4 changes: 3 additions & 1 deletion icu4c/source/i18n/timezone.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -739,7 +739,9 @@ void TimeZone::getOffset(UDate date, UBool local, int32_t& rawOffset,
static_cast<uint8_t>(dow), millis,
Grego::monthLength(year, month),
ec) - rawOffset;

if (U_FAILURE(ec)) {
return;
}
// Recompute if local==true, dstOffset!=0.
if (pass!=0 || !local || dstOffset == 0) {
break;
Expand Down
2 changes: 1 addition & 1 deletion icu4c/source/i18n/tzfmt.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -697,8 +697,8 @@ TimeZoneFormat::format(UTimeZoneFormatStyle style, const TimeZone& tz, UDate dat
UErrorCode status = U_ZERO_ERROR;
int32_t rawOffset, dstOffset;
tz.getOffset(date, false, rawOffset, dstOffset, status);
int32_t offset = rawOffset + dstOffset;
if (U_SUCCESS(status)) {
int32_t offset = rawOffset + dstOffset;
switch (style) {
case UTZFMT_STYLE_GENERIC_LOCATION:
case UTZFMT_STYLE_GENERIC_LONG:
Expand Down
5 changes: 4 additions & 1 deletion icu4c/source/i18n/ucol_sit.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -578,7 +578,10 @@ ucol_normalizeShortDefinitionString(const char *definition,
if(U_FAILURE(*status)) {
return 0;
}

if(!destination && capacity != 0) {
*status = U_ILLEGAL_ARGUMENT_ERROR;
return 0;
}
if(destination) {
uprv_memset(destination, 0, capacity*sizeof(char));
}
Expand Down
2 changes: 1 addition & 1 deletion icu4c/source/i18n/uregex.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1877,7 +1877,7 @@ int32_t RegexCImpl::split(RegularExpression *regexp,
i++;

// Set up to extract the capture group contents into the dest buffer.
destFields[i] = &destBuf[destIdx];
destFields[i] = (destBuf == nullptr) ? nullptr : &destBuf[destIdx];
tStatus = U_ZERO_ERROR;
int32_t t = uregex_group(reinterpret_cast<URegularExpression*>(regexp),
groupNum,
Expand Down