Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 8 additions & 4 deletions Source/astcenccli_image.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// SPDX-License-Identifier: Apache-2.0
// ----------------------------------------------------------------------------
// Copyright 2011-2022 Arm Limited
// Copyright 2011-2026 Arm Limited
//
// Licensed under the Apache License, Version 2.0 (the "License"); you may not
// use this file except in compliance with the License. You may obtain a copy
Expand Down Expand Up @@ -41,6 +41,10 @@ astcenc_image_ptr alloc_image(
img->data_type = ASTCENC_TYPE_U8;
img->data = nullptr;

// Ensure this is done as a size_t to avoid overflow - calling code has
// checked that the product will fit in a size_t without overflowing.
size_t plane_components = static_cast<size_t>(dim_x) * dim_y * 4;

void** data = new void*[dim_z] {};
img->data = data;

Expand All @@ -49,15 +53,15 @@ astcenc_image_ptr alloc_image(
img->data_type = ASTCENC_TYPE_U8;
for (unsigned int z = 0; z < dim_z; z++)
{
data[z] = new uint8_t[dim_x * dim_y * 4];
data[z] = new uint8_t[plane_components];
}
}
else if (bitness == 16)
{
img->data_type = ASTCENC_TYPE_F16;
for (unsigned int z = 0; z < dim_z; z++)
{
data[z] = new uint16_t[dim_x * dim_y * 4];
data[z] = new uint16_t[plane_components];
}
}
else // if (bitness == 32)
Expand All @@ -66,7 +70,7 @@ astcenc_image_ptr alloc_image(
img->data_type = ASTCENC_TYPE_F32;
for (unsigned int z = 0; z < dim_z; z++)
{
data[z] = new float[dim_x * dim_y * 4];
data[z] = new float[plane_components];
}
}

Expand Down
Loading