Add Chromium-only Blender WebEngine parity work

This commit is contained in:
mes123456
2026-08-12 04:47:48 -04:00
commit 9fd26010f6
18225 changed files with 11622124 additions and 0 deletions

View File

@@ -0,0 +1,60 @@
/* SPDX-FileCopyrightText: 2014-2022 Blender Authors
*
* SPDX-License-Identifier: Apache-2.0 */
#include "testing/testing.h"
#include "BLI_utildefines.h"
#include "MEM_guardedalloc.h"
#include "guardedalloc_test_base.h"
#define CHECK_ALIGNMENT(ptr, align) EXPECT_EQ(size_t(ptr) % align, 0)
namespace {
void DoBasicAlignmentChecks(const int alignment)
{
int *foo, *bar;
foo = (int *)MEM_new_uninitialized_aligned(sizeof(int) * 10, alignment, "test");
CHECK_ALIGNMENT(foo, alignment);
bar = (int *)MEM_dupalloc_void(foo);
CHECK_ALIGNMENT(bar, alignment);
MEM_delete(bar);
foo = (int *)MEM_realloc_uninitialized(foo, sizeof(int) * 5);
CHECK_ALIGNMENT(foo, alignment);
foo = (int *)MEM_realloc_zeroed(foo, sizeof(int) * 5);
CHECK_ALIGNMENT(foo, alignment);
MEM_delete(foo);
}
} // namespace
TEST_F(LockFreeAllocatorTest, MEM_new_uninitialized_aligned)
{
DoBasicAlignmentChecks(1);
DoBasicAlignmentChecks(2);
DoBasicAlignmentChecks(4);
DoBasicAlignmentChecks(8);
DoBasicAlignmentChecks(16);
DoBasicAlignmentChecks(32);
DoBasicAlignmentChecks(256);
DoBasicAlignmentChecks(512);
}
TEST_F(GuardedAllocatorTest, MEM_new_uninitialized_aligned)
{
DoBasicAlignmentChecks(1);
DoBasicAlignmentChecks(2);
DoBasicAlignmentChecks(4);
DoBasicAlignmentChecks(8);
DoBasicAlignmentChecks(16);
DoBasicAlignmentChecks(32);
DoBasicAlignmentChecks(256);
DoBasicAlignmentChecks(512);
}

View File

@@ -0,0 +1,62 @@
/* SPDX-FileCopyrightText: 2018-2022 Blender Authors
*
* SPDX-License-Identifier: Apache-2.0 */
#include "testing/testing.h"
#include "MEM_guardedalloc.h"
#include "guardedalloc_test_base.h"
/* We expect to abort on integer overflow, to prevent possible exploits. */
#if defined(__GNUC__) && !defined(__clang__)
/* Disable since it's the purpose of this test. */
# pragma GCC diagnostic ignored "-Walloc-size-larger-than="
#endif
namespace {
void MallocArray(size_t len, size_t size)
{
void *mem = MEM_new_array_uninitialized(len, size, "MallocArray");
if (mem) {
MEM_delete_void(mem);
}
}
void CallocArray(size_t len, size_t size)
{
void *mem = MEM_new_array_zeroed(len, size, "CallocArray");
if (mem) {
MEM_delete_void(mem);
}
}
} // namespace
TEST_F(LockFreeAllocatorTest, LockfreeIntegerOverflow)
{
MallocArray(1, SIZE_MAX);
CallocArray(SIZE_MAX, 1);
MallocArray(SIZE_MAX / 2, 2);
CallocArray(SIZE_MAX / 1234567, 1234567);
EXPECT_EXIT(MallocArray(SIZE_MAX, 2), ABORT_PREDICATE, "");
EXPECT_EXIT(CallocArray(7, SIZE_MAX), ABORT_PREDICATE, "");
EXPECT_EXIT(MallocArray(SIZE_MAX, 12345567), ABORT_PREDICATE, "");
EXPECT_EXIT(CallocArray(SIZE_MAX, SIZE_MAX), ABORT_PREDICATE, "");
}
TEST_F(GuardedAllocatorTest, GuardedIntegerOverflow)
{
MallocArray(1, SIZE_MAX);
CallocArray(SIZE_MAX, 1);
MallocArray(SIZE_MAX / 2, 2);
CallocArray(SIZE_MAX / 1234567, 1234567);
EXPECT_EXIT(MallocArray(SIZE_MAX, 2), ABORT_PREDICATE, "");
EXPECT_EXIT(CallocArray(7, SIZE_MAX), ABORT_PREDICATE, "");
EXPECT_EXIT(MallocArray(SIZE_MAX, 12345567), ABORT_PREDICATE, "");
EXPECT_EXIT(CallocArray(SIZE_MAX, SIZE_MAX), ABORT_PREDICATE, "");
}

View File

@@ -0,0 +1,84 @@
/* SPDX-FileCopyrightText: 2026 Blender Authors
*
* SPDX-License-Identifier: Apache-2.0 */
#include "testing/testing.h"
#include "MEM_safe_multiply.h"
namespace {
template<typename T> void expect_ok(T a, T b, T expected)
{
T result = T(123);
EXPECT_TRUE(MEM_size_safe_multiply(a, b, &result));
EXPECT_EQ(result, expected);
}
template<typename T> void expect_overflow(T a, T b)
{
T result = T(123);
EXPECT_FALSE(MEM_size_safe_multiply(a, b, &result));
EXPECT_EQ(result, T(0));
}
} // namespace
TEST(safe_multiply, SizeT)
{
/* Value near overflow that should just fit. */
const size_t near_overflow = (size_t(1) << (sizeof(size_t) * 8 / 2)) - 1;
expect_ok<size_t>(0, 0, 0);
expect_ok<size_t>(0, 42, 0);
expect_ok<size_t>(42, 0, 0);
expect_ok<size_t>(0, SIZE_MAX, 0);
expect_ok<size_t>(SIZE_MAX, 0, 0);
expect_ok<size_t>(1, 1, 1);
expect_ok<size_t>(123, 456, 123 * 456);
expect_ok<size_t>(1, SIZE_MAX, SIZE_MAX);
expect_ok<size_t>(SIZE_MAX, 1, SIZE_MAX);
expect_ok<size_t>(near_overflow, near_overflow, near_overflow * near_overflow);
expect_ok<size_t>(near_overflow + 1, 2, (near_overflow + 1) * 2);
expect_ok<size_t>(SIZE_MAX / 2, 2, (SIZE_MAX / 2) * 2);
expect_ok<size_t>(SIZE_MAX / 1234567, 1234567, (SIZE_MAX / 1234567) * 1234567);
expect_overflow<size_t>(SIZE_MAX, 2);
expect_overflow<size_t>(2, SIZE_MAX);
expect_overflow<size_t>(SIZE_MAX, SIZE_MAX);
expect_overflow<size_t>(SIZE_MAX / 2 + 1, 2);
expect_overflow<size_t>(SIZE_MAX, 12345567);
}
TEST(safe_multiply, Int64)
{
expect_ok<int64_t>(0, 0, 0);
expect_ok<int64_t>(0, 42, 0);
expect_ok<int64_t>(42, 0, 0);
expect_ok<int64_t>(1, 1, 1);
expect_ok<int64_t>(123, 456, 123 * 456);
expect_ok<int64_t>(2147483647, 2147483647, int64_t(2147483647) * 2147483647);
if constexpr (sizeof(size_t) >= sizeof(int64_t)) {
/* OK on 64 bit. */
expect_ok<int64_t>(1, INT64_MAX, INT64_MAX);
expect_ok<int64_t>(int64_t(1) << 31, 2, int64_t(1) << 32);
expect_ok<int64_t>(INT64_MAX / 2, 2, (INT64_MAX / 2) * 2);
}
else {
/* Overflow on 32 bit. */
expect_overflow<int64_t>(1, INT64_MAX);
expect_overflow<int64_t>(int64_t(1) << 31, 2);
expect_overflow<int64_t>(INT64_MAX / 2, 2);
}
expect_overflow<int64_t>(-1, 1);
expect_overflow<int64_t>(1, -1);
expect_overflow<int64_t>(-5, -5);
expect_overflow<int64_t>(INT64_MIN, 1);
expect_overflow<int64_t>(-1000000, 1000000);
expect_overflow<int64_t>(INT64_MAX, 2);
expect_overflow<int64_t>(2, INT64_MAX);
expect_overflow<int64_t>(INT64_MAX, INT64_MAX);
expect_overflow<int64_t>(INT64_MAX / 2 + 1, 2);
}

View File

@@ -0,0 +1,28 @@
/* SPDX-FileCopyrightText: 2020-2022 Blender Authors
*
* SPDX-License-Identifier: Apache-2.0 */
#ifndef __GUARDEDALLOC_TEST_UTIL_H__
#define __GUARDEDALLOC_TEST_UTIL_H__
#include "testing/testing.h"
#include "MEM_guardedalloc.h"
class LockFreeAllocatorTest : public ::testing::Test {
protected:
void SetUp() override
{
MEM_use_lockfree_allocator();
}
};
class GuardedAllocatorTest : public ::testing::Test {
protected:
void SetUp() override
{
MEM_use_guarded_allocator();
}
};
#endif // __GUARDEDALLOC_TEST_UTIL_H__