Skip to content

Commit

Permalink
Reject invalid encodings during decode
Browse files Browse the repository at this point in the history
  • Loading branch information
solidpixel committed Aug 21, 2021
1 parent 04c5e77 commit 5c5dee5
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion Source/astcenc_symbolic_physical.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -301,6 +301,7 @@ void physical_to_symbolic(
if (rsvbits != 3)
{
scb.block_type = SYM_BTYPE_ERROR;
return;
}

int vx_low_s = read_bits(8, 12, pcb.data) | (read_bits(5, 12 + 8, pcb.data) << 8);
Expand All @@ -313,6 +314,7 @@ void physical_to_symbolic(
if ((vx_low_s >= vx_high_s || vx_low_t >= vx_high_t) && !all_ones)
{
scb.block_type = SYM_BTYPE_ERROR;
return;
}
}
else
Expand All @@ -330,6 +332,7 @@ void physical_to_symbolic(
if ((vx_low_s >= vx_high_s || vx_low_t >= vx_high_t || vx_low_p >= vx_high_p) && !all_ones)
{
scb.block_type = SYM_BTYPE_ERROR;
return;
}
}

Expand Down Expand Up @@ -384,6 +387,7 @@ void physical_to_symbolic(
if (is_dual_plane && partition_count == 4)
{
scb.block_type = SYM_BTYPE_ERROR;
return;
}

scb.color_formats_matched = 0;
Expand Down Expand Up @@ -449,6 +453,7 @@ void physical_to_symbolic(
if (color_integer_count > 18)
{
scb.block_type = SYM_BTYPE_ERROR;
return;
}

// Determine the color endpoint format to use
Expand All @@ -465,13 +470,14 @@ void physical_to_symbolic(
}

int color_quant_level = quant_mode_table[color_integer_count >> 1][color_bits];
scb.quant_mode = (quant_method)color_quant_level;
if (color_quant_level < QUANT_6)
{
scb.block_type = SYM_BTYPE_ERROR;
return;
}

// Unpack the integer color values and assign to endpoints
scb.quant_mode = (quant_method)color_quant_level;
uint8_t values_to_decode[32];
decode_ise((quant_method)color_quant_level, color_integer_count, pcb.data, values_to_decode, (partition_count == 1 ? 17 : 19 + PARTITION_INDEX_BITS));

Expand Down

0 comments on commit 5c5dee5

Please sign in to comment.