mirror of
https://github.com/encounter/dawn-cmake.git
synced 2025-12-17 08:57:26 +00:00
Fix overflow in CommandAllocator
It was essentially checking "currentPtr + commandSize <= endPtr" and commandSize could make currentPtr overflow, making the comparison succeed when it shouldn't have. This was caught through flakiness of the LargeCommands allocator test. Added a test provoking an overflow in Allocate and checking nullptr is returned. BUG= Change-Id: I8ae4dad5b33c9d2005027c4d45b110ee0c65dd9a Reviewed-on: https://dawn-review.googlesource.com/c/2841 Commit-Queue: Corentin Wallez <cwallez@chromium.org> Reviewed-by: Stephen White <senorblanco@chromium.org>
This commit is contained in:
committed by
Commit Bot service account
parent
0cdf9e09c4
commit
1c92c159ad
@@ -16,6 +16,8 @@
|
||||
|
||||
#include "dawn_native/CommandAllocator.h"
|
||||
|
||||
#include <limits>
|
||||
|
||||
using namespace dawn_native;
|
||||
|
||||
// Definition of the command types used in the tests
|
||||
@@ -362,3 +364,40 @@ TEST(CommandAllocator, EmptyIterator) {
|
||||
iterator2.DataWasDestroyed();
|
||||
}
|
||||
}
|
||||
|
||||
template <size_t A>
|
||||
struct alignas(A) AlignedStruct {
|
||||
char dummy;
|
||||
};
|
||||
|
||||
// Test for overflows in Allocate's computations, size 1 variant
|
||||
TEST(CommandAllocator, AllocationOverflow_1) {
|
||||
CommandAllocator allocator;
|
||||
AlignedStruct<1>* data =
|
||||
allocator.AllocateData<AlignedStruct<1>>(std::numeric_limits<size_t>::max() / 1);
|
||||
ASSERT_EQ(data, nullptr);
|
||||
}
|
||||
|
||||
// Test for overflows in Allocate's computations, size 2 variant
|
||||
TEST(CommandAllocator, AllocationOverflow_2) {
|
||||
CommandAllocator allocator;
|
||||
AlignedStruct<2>* data =
|
||||
allocator.AllocateData<AlignedStruct<2>>(std::numeric_limits<size_t>::max() / 2);
|
||||
ASSERT_EQ(data, nullptr);
|
||||
}
|
||||
|
||||
// Test for overflows in Allocate's computations, size 4 variant
|
||||
TEST(CommandAllocator, AllocationOverflow_4) {
|
||||
CommandAllocator allocator;
|
||||
AlignedStruct<4>* data =
|
||||
allocator.AllocateData<AlignedStruct<4>>(std::numeric_limits<size_t>::max() / 4);
|
||||
ASSERT_EQ(data, nullptr);
|
||||
}
|
||||
|
||||
// Test for overflows in Allocate's computations, size 8 variant
|
||||
TEST(CommandAllocator, AllocationOverflow_8) {
|
||||
CommandAllocator allocator;
|
||||
AlignedStruct<8>* data =
|
||||
allocator.AllocateData<AlignedStruct<8>>(std::numeric_limits<size_t>::max() / 8);
|
||||
ASSERT_EQ(data, nullptr);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user