fix crash when importing textures that exceed expected size (#42)

This commit is contained in:
Isaac0-dev 2024-05-14 09:38:21 +10:00 committed by GitHub
parent 626970c022
commit 45d42dbf73
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with 8 additions and 0 deletions

View File

@ -416,6 +416,7 @@ static void import_texture_rgba32(int tile) {
static void import_texture_rgba16(int tile) {
tile = tile % RDP_TILES;
if (!rdp.loaded_texture[tile].addr) { return; }
if (rdp.loaded_texture[tile].size_bytes * 2 > 8192) { return; }
uint8_t rgba32_buf[8192];
for (uint32_t i = 0; i < rdp.loaded_texture[tile].size_bytes / 2; i++) {
@ -439,6 +440,7 @@ static void import_texture_rgba16(int tile) {
static void import_texture_ia4(int tile) {
tile = tile % RDP_TILES;
if (!rdp.loaded_texture[tile].addr) { return; }
if (rdp.loaded_texture[tile].size_bytes * 8 > 32768) { return; }
uint8_t rgba32_buf[32768];
for (uint32_t i = 0; i < rdp.loaded_texture[tile].size_bytes * 2; i++) {
@ -464,6 +466,7 @@ static void import_texture_ia4(int tile) {
static void import_texture_ia8(int tile) {
tile = tile % RDP_TILES;
if (!rdp.loaded_texture[tile].addr) { return; }
if (rdp.loaded_texture[tile].size_bytes * 4 > 16384) { return; }
uint8_t rgba32_buf[16384];
for (uint32_t i = 0; i < rdp.loaded_texture[tile].size_bytes; i++) {
@ -487,6 +490,7 @@ static void import_texture_ia8(int tile) {
static void import_texture_ia16(int tile) {
tile = tile % RDP_TILES;
if (!rdp.loaded_texture[tile].addr) { return; }
if (rdp.loaded_texture[tile].size_bytes * 2 > 8192) { return; }
uint8_t rgba32_buf[8192];
for (uint32_t i = 0; i < rdp.loaded_texture[tile].size_bytes / 2; i++) {
@ -510,6 +514,7 @@ static void import_texture_ia16(int tile) {
static void import_texture_i4(int tile) {
tile = tile % RDP_TILES;
if (!rdp.loaded_texture[tile].addr) { return; }
if (rdp.loaded_texture[tile].size_bytes * 8 > 32768) { return; }
uint8_t rgba32_buf[32768];
for (uint32_t i = 0; i < rdp.loaded_texture[tile].size_bytes * 2; i++) {
@ -530,6 +535,7 @@ static void import_texture_i4(int tile) {
static void import_texture_i8(int tile) {
tile = tile % RDP_TILES;
if (!rdp.loaded_texture[tile].addr) { return; }
if (rdp.loaded_texture[tile].size_bytes * 4 > 16384) { return; }
uint8_t rgba32_buf[16384];
for (uint32_t i = 0; i < rdp.loaded_texture[tile].size_bytes; i++) {
@ -549,6 +555,7 @@ static void import_texture_i8(int tile) {
static void import_texture_ci4(int tile) {
tile = tile % RDP_TILES;
if (!rdp.loaded_texture[tile].addr) { return; }
if (rdp.loaded_texture[tile].size_bytes * 8 > 32768) { return; }
uint8_t rgba32_buf[32768];
for (uint32_t i = 0; i < rdp.loaded_texture[tile].size_bytes * 2; i++) {
@ -574,6 +581,7 @@ static void import_texture_ci4(int tile) {
static void import_texture_ci8(int tile) {
tile = tile % RDP_TILES;
if (!rdp.loaded_texture[tile].addr) { return; }
if (rdp.loaded_texture[tile].size_bytes * 4 > 16384) { return; }
uint8_t rgba32_buf[16384];
for (uint32_t i = 0; i < rdp.loaded_texture[tile].size_bytes; i++) {