mirror of
https://repo.dactyloidae.xyz/Dactyloidae/UXP.git
synced 2026-09-29 20:07:30 +09:00
Bug 1440926 - Use overflow-checking math when computing Big5 max length. r=emk, a=RyanVM
MozReview-Commit-ID: 1Gney5cYyhu
This commit is contained in:
parent
9593a8c761
commit
128b5dfa13
2 changed files with 26 additions and 7 deletions
|
|
@ -152,7 +152,17 @@ nsBIG5ToUnicode::GetMaxLength(const char* aSrc,
|
||||||
{
|
{
|
||||||
// The length of the output in UTF-16 code units never exceeds the length
|
// The length of the output in UTF-16 code units never exceeds the length
|
||||||
// of the input in bytes.
|
// of the input in bytes.
|
||||||
*aDestLength = aSrcLength + (mPendingTrail ? 1 : 0) + (mBig5Lead ? 1 : 0);
|
mozilla::CheckedInt32 length = aSrcLength;
|
||||||
|
if (mPendingTrail) {
|
||||||
|
length += 1;
|
||||||
|
}
|
||||||
|
if (mBig5Lead) {
|
||||||
|
length += 1;
|
||||||
|
}
|
||||||
|
if (!length.isValid()) {
|
||||||
|
return NS_ERROR_OUT_OF_MEMORY;
|
||||||
|
}
|
||||||
|
*aDestLength = length.value();
|
||||||
return NS_OK;
|
return NS_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -211,12 +211,21 @@ nsUnicodeToBIG5::GetMaxLength(const char16_t* aSrc,
|
||||||
int32_t aSrcLength,
|
int32_t aSrcLength,
|
||||||
int32_t* aDestLength)
|
int32_t* aDestLength)
|
||||||
{
|
{
|
||||||
*aDestLength = (aSrcLength * 2) +
|
mozilla::CheckedInt32 length = aSrcLength;
|
||||||
(mPendingTrail ? 1 : 0) +
|
length *= 2;
|
||||||
// If the lead ends up being paired, the bytes produced
|
if (mPendingTrail) {
|
||||||
// are already included above.
|
length += 1;
|
||||||
// If not, it produces a single '?'.
|
}
|
||||||
(mUtf16Lead ? 1 : 0);
|
// If the lead ends up being paired, the bytes produced
|
||||||
|
// are already included above.
|
||||||
|
// If not, it produces a single '?'.
|
||||||
|
if (mUtf16Lead) {
|
||||||
|
length += 1;
|
||||||
|
}
|
||||||
|
if (!length.isValid()) {
|
||||||
|
return NS_ERROR_OUT_OF_MEMORY;
|
||||||
|
}
|
||||||
|
*aDestLength = length.value();
|
||||||
return NS_OK;
|
return NS_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue