Use a common helper for std::nothrow

It's come up multiple times that ASAN doesn't support
std::nothrow which leads to OOM bugs filed by the fuzzers.
Use a common helper to avoid this and return nullptr for large
allocations when ASAN is enabled.

Bug: none
Change-Id: I492b4ff4e498cf82d4ca08ba849671d3d16b9cfb
Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/36280
Reviewed-by: Jiawei Shao <jiawei.shao@intel.com>
Reviewed-by: Corentin Wallez <cwallez@chromium.org>
Commit-Queue: Austin Eng <enga@chromium.org>
This commit is contained in:
Austin Eng
2021-01-05 07:40:48 +00:00
committed by Commit Bot service account
parent c120b02dbe
commit e3fd026108
7 changed files with 47 additions and 14 deletions

View File

@@ -14,6 +14,7 @@
#include "dawn_native/Buffer.h"
#include "common/Alloc.h"
#include "common/Assert.h"
#include "dawn_native/Commands.h"
#include "dawn_native/Device.h"
@@ -56,8 +57,8 @@ namespace dawn_native {
descriptor->size < uint64_t(std::numeric_limits<size_t>::max());
if (isValidSize) {
mFakeMappedData = std::unique_ptr<uint8_t[]>(new (std::nothrow)
uint8_t[descriptor->size]);
mFakeMappedData =
std::unique_ptr<uint8_t[]>(AllocNoThrow<uint8_t>(descriptor->size));
}
}
}
@@ -298,7 +299,8 @@ namespace dawn_native {
if (mSize == 0) {
return reinterpret_cast<uint8_t*>(intptr_t(0xCAFED00D));
}
return static_cast<uint8_t*>(GetMappedPointerImpl()) + offset;
uint8_t* start = static_cast<uint8_t*>(GetMappedPointerImpl());
return start == nullptr ? nullptr : start + offset;
}
void BufferBase::Destroy() {