summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorGravatar ameerj2021-01-19 19:54:28 -0500
committerGravatar ameerj2021-03-13 12:16:03 -0500
commitc7553abe894ddac84fe8417a12ec51d5ab60dc58 (patch)
tree88935acf2a66ec6e80dcd927f3c1f6bb9f5af229 /src
parentrenderer_vulkan: Accelerate ASTC decoding (diff)
downloadyuzu-c7553abe894ddac84fe8417a12ec51d5ab60dc58.tar.gz
yuzu-c7553abe894ddac84fe8417a12ec51d5ab60dc58.tar.xz
yuzu-c7553abe894ddac84fe8417a12ec51d5ab60dc58.zip
astc_decoder: Fix out of bounds memory access
resolves a crash with some anamolous textures found in Astral Chain.
Diffstat (limited to 'src')
-rw-r--r--src/video_core/host_shaders/astc_decoder.comp12
1 files changed, 10 insertions, 2 deletions
diff --git a/src/video_core/host_shaders/astc_decoder.comp b/src/video_core/host_shaders/astc_decoder.comp
index 2ddac2e1d..5be716309 100644
--- a/src/video_core/host_shaders/astc_decoder.comp
+++ b/src/video_core/host_shaders/astc_decoder.comp
@@ -339,6 +339,9 @@ uint Select2DPartition(uint seed, uint x, uint y, uint partition_count, bool sma
339} 339}
340 340
341uint ReadBit() { 341uint ReadBit() {
342 if (current_index >= local_buff.length()) {
343 return 0;
344 }
342 uint bit = bitfieldExtract(local_buff[current_index], bitsread, 1); 345 uint bit = bitfieldExtract(local_buff[current_index], bitsread, 1);
343 bitsread++; 346 bitsread++;
344 total_bitsread++; 347 total_bitsread++;
@@ -1170,12 +1173,17 @@ void DecompressBlock(ivec3 coord, uint block_index) {
1170 plane_selector_bits = 2; 1173 plane_selector_bits = 2;
1171 } 1174 }
1172 remaining_bits -= plane_selector_bits; 1175 remaining_bits -= plane_selector_bits;
1176 if (remaining_bits > 128) {
1177 // Bad data, more remaining bits than 4 bytes
1178 // return early
1179 return;
1180 }
1173 // Read color data... 1181 // Read color data...
1174 uint color_data_bits = remaining_bits; 1182 uint color_data_bits = remaining_bits;
1175 while (remaining_bits > 0) { 1183 while (remaining_bits > 0) {
1176 uint nb = min(remaining_bits, 8); 1184 int nb = int(min(remaining_bits, 8U));
1177 uint b = StreamBits(nb); 1185 uint b = StreamBits(nb);
1178 color_endpoint_data[ced_pointer] = uint(bitfieldExtract(b, 0, 8)); 1186 color_endpoint_data[ced_pointer] = uint(bitfieldExtract(b, 0, nb));
1179 ced_pointer++; 1187 ced_pointer++;
1180 remaining_bits -= nb; 1188 remaining_bits -= nb;
1181 } 1189 }