Null: Make Increment/DecrementMemoryUsage use uint64_t.

Otherwise on 32-bit platforms, creation of a buffer bigger than the max
size_t would overflow the check and no OOM would be produced.

Bug: chromium:1099621

Change-Id: I987a338b150d10c0eabc3eb5fb3b815a5c2a5ca2
Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/23960
Reviewed-by: Austin Eng <enga@chromium.org>
Reviewed-by: Kai Ninomiya <kainino@chromium.org>
Commit-Queue: Kai Ninomiya <kainino@chromium.org>
This commit is contained in:
Corentin Wallez 2020-06-29 20:03:16 +00:00 committed by Commit Bot service account
parent 1c9e045024
commit b231c7fb71
2 changed files with 6 additions and 6 deletions

View File

@ -209,8 +209,8 @@ namespace dawn_native { namespace null {
return {};
}
MaybeError Device::IncrementMemoryUsage(size_t bytes) {
static_assert(kMaxMemoryUsage <= std::numeric_limits<size_t>::max() / 2, "");
MaybeError Device::IncrementMemoryUsage(uint64_t bytes) {
static_assert(kMaxMemoryUsage <= std::numeric_limits<size_t>::max(), "");
if (bytes > kMaxMemoryUsage || mMemoryUsage + bytes > kMaxMemoryUsage) {
return DAWN_OUT_OF_MEMORY_ERROR("Out of memory.");
}
@ -218,7 +218,7 @@ namespace dawn_native { namespace null {
return {};
}
void Device::DecrementMemoryUsage(size_t bytes) {
void Device::DecrementMemoryUsage(uint64_t bytes) {
ASSERT(mMemoryUsage >= bytes);
mMemoryUsage -= bytes;
}

View File

@ -106,8 +106,8 @@ namespace dawn_native { namespace null {
uint64_t destinationOffset,
uint64_t size) override;
MaybeError IncrementMemoryUsage(size_t bytes);
void DecrementMemoryUsage(size_t bytes);
MaybeError IncrementMemoryUsage(uint64_t bytes);
void DecrementMemoryUsage(uint64_t bytes);
private:
using DeviceBase::DeviceBase;
@ -147,7 +147,7 @@ namespace dawn_native { namespace null {
std::vector<std::unique_ptr<PendingOperation>> mPendingOperations;
static constexpr size_t kMaxMemoryUsage = 256 * 1024 * 1024;
static constexpr uint64_t kMaxMemoryUsage = 256 * 1024 * 1024;
size_t mMemoryUsage = 0;
};