mirror of
https://repo.dactyloidae.xyz/Dactyloidae/UXP.git
synced 2026-09-03 22:38:41 +09:00
Apply CheckedInt to infoLength for preventing it from overflowing in the future.
CheckedInt propagates the mIsValid in each add operation so that it avoids needing a bunch of code for the overflow check in each add operation. Additionally, it avoids mismatching parameters between the computing result and the additional overflow check. This patch uses CheckedInt to take advantage of those implicit features of it.
This commit is contained in:
parent
bf30898e2c
commit
429b2125de
1 changed files with 10 additions and 13 deletions
|
|
@ -23,6 +23,7 @@
|
|||
#include "mozilla/AppProcessChecker.h"
|
||||
#include "mozilla/AutoRestore.h"
|
||||
#include "mozilla/Casting.h"
|
||||
#include "mozilla/CheckedInt.h"
|
||||
#include "mozilla/EndianUtils.h"
|
||||
#include "mozilla/ErrorNames.h"
|
||||
#include "mozilla/LazyIdleThread.h"
|
||||
|
|
@ -782,29 +783,25 @@ MakeCompressedIndexDataValues(
|
|||
|
||||
MOZ_ASSERT(!keyBuffer.IsEmpty());
|
||||
|
||||
// Don't let |infoLength| overflow.
|
||||
if (NS_WARN_IF(UINT32_MAX - keyBuffer.Length() <
|
||||
CompressedByteCountForIndexId(info.mIndexId) +
|
||||
CompressedByteCountForNumber(keyBufferLength) +
|
||||
CompressedByteCountForNumber(sortKeyBufferLength))) {
|
||||
IDB_REPORT_INTERNAL_ERR();
|
||||
return NS_ERROR_DOM_INDEXEDDB_UNKNOWN_ERR;
|
||||
}
|
||||
|
||||
const uint32_t infoLength =
|
||||
CompressedByteCountForIndexId(info.mIndexId) +
|
||||
const CheckedUint32 infoLength =
|
||||
CheckedUint32(CompressedByteCountForIndexId(info.mIndexId)) +
|
||||
CompressedByteCountForNumber(keyBufferLength) +
|
||||
CompressedByteCountForNumber(sortKeyBufferLength) +
|
||||
keyBufferLength +
|
||||
sortKeyBufferLength;
|
||||
|
||||
// Don't let |blobDataLength| overflow.
|
||||
if (NS_WARN_IF(UINT32_MAX - infoLength < blobDataLength)) {
|
||||
// Don't let |infoLength| overflow.
|
||||
if (NS_WARN_IF(!infoLength.isValid())) {
|
||||
IDB_REPORT_INTERNAL_ERR();
|
||||
return NS_ERROR_DOM_INDEXEDDB_UNKNOWN_ERR;
|
||||
}
|
||||
|
||||
blobDataLength += infoLength;
|
||||
// Don't let |blobDataLength| overflow.
|
||||
if (NS_WARN_IF(UINT32_MAX - infoLength.value() < blobDataLength)) {
|
||||
IDB_REPORT_INTERNAL_ERR();
|
||||
return NS_ERROR_DOM_INDEXEDDB_UNKNOWN_ERR;
|
||||
}
|
||||
|
||||
blobDataLength += infoLength.value();
|
||||
}
|
||||
|
||||
UniqueFreePtr<uint8_t> blobData(
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue