diff --git a/Source/astcenc_block_sizes.cpp b/Source/astcenc_block_sizes.cpp index e7b5348aa0b65c0731d0b20418af4adaa3490ca4..0093bf55d9b04fbb2a299aa50db88918f09cc85b 100644 --- a/Source/astcenc_block_sizes.cpp +++ b/Source/astcenc_block_sizes.cpp @@ -821,6 +821,12 @@ static void construct_block_size_descriptor_2d( // Gather all the decimation grids that can be used with the current block #if !defined(ASTCENC_DECOMPRESS_ONLY) const float *percentiles = get_2d_percentile_table(x_texels, y_texels); + if (percentiles == nullptr) { + delete wb; +#ifdef ASTC_CUSTOMIZED_ENABLE + return false; +#endif + } float always_cutoff = (privateProfile != HIGH_QUALITY_PROFILE) ? 1.0f : 0.0f; #else // Unused in decompress-only builds diff --git a/Source/astcenc_color_quantize.cpp b/Source/astcenc_color_quantize.cpp index 4ac0aff58dcc72aa9f93f6f92f56400c30b0209b..7b61a7ccd53823ed2cc4de523a0919ee0b200ae1 100644 --- a/Source/astcenc_color_quantize.cpp +++ b/Source/astcenc_color_quantize.cpp @@ -73,6 +73,7 @@ static inline uint8_t quant_color( quant_method quant_level, int value ) { + value = astc::clamp(value, 0, 255); // 255: maximum value int index = value * 2 + 1; return color_unquant_to_uquant_tables[quant_level - QUANT_6][index]; } diff --git a/Source/astcenc_percentile_tables.cpp b/Source/astcenc_percentile_tables.cpp index 448ddcc968e0dbac52b221329294871e36ed3b55..98f5777566aa006c9be3190b2492687877bd9354 100644 --- a/Source/astcenc_percentile_tables.cpp +++ b/Source/astcenc_percentile_tables.cpp @@ -1168,6 +1168,10 @@ const float *get_2d_percentile_table( ) { float* unpacked_table = new float[WEIGHTS_MAX_BLOCK_MODES]; const packed_percentile_table *apt = get_packed_table(xdim, ydim); + if (apt == nullptr) { + delete[] unpacked_table; + return nullptr; + } // Set the default percentile for (unsigned int i = 0; i < WEIGHTS_MAX_BLOCK_MODES; i++) diff --git a/Source/astcenc_pick_best_endpoint_format.cpp b/Source/astcenc_pick_best_endpoint_format.cpp index d3b9f6c296efe2857e9ecfc941d9a59606e1c0e0..2b97bd95c5efe7e46a9cee78a9bea3cd94251455 100644 --- a/Source/astcenc_pick_best_endpoint_format.cpp +++ b/Source/astcenc_pick_best_endpoint_format.cpp @@ -917,6 +917,9 @@ static float two_partitions_find_best_combination_for_bitcount( if (ql >= QUANT_6) { + if (best_integer_count < 2) { // 2: minimum integer_count + return ERROR_CALC_DEFAULT; + } for (int i = 0; i < 2; i++) { best_formats[i] = best_combined_format[ql][best_integer_count - 2][i]; @@ -1042,6 +1045,9 @@ static float three_partitions_find_best_combination_for_bitcount( if (ql >= QUANT_6) { + if (best_integer_count < 3) { // 3: minimum integer_count + return ERROR_CALC_DEFAULT; + } for (int i = 0; i < 3; i++) { best_formats[i] = best_combined_format[ql][best_integer_count - 3][i]; @@ -1178,6 +1184,9 @@ static float four_partitions_find_best_combination_for_bitcount( if (ql >= QUANT_6) { + if (best_integer_count < 4) { // 4: minimum integer_count + return ERROR_CALC_DEFAULT; + } for (int i = 0; i < 4; i++) { best_formats[i] = best_combined_format[ql][best_integer_count - 4][i];