diff --git a/src/rct1.c b/src/rct1.c index 2715537946..64363c3185 100644 --- a/src/rct1.c +++ b/src/rct1.c @@ -38,8 +38,8 @@ bool rct1_read_sc4(const char *path, rct1_s4 *s4) decodedBuffer = malloc(sizeof(rct1_s4)); decodedLength = (fileType & FILE_VERSION_MASK) == FILE_VERSION_RCT1 ? - sawyercoding_decode_sv4(buffer, decodedBuffer, length) : - sawyercoding_decode_sc4(buffer, decodedBuffer, length); + sawyercoding_decode_sv4(buffer, decodedBuffer, length, sizeof(rct1_s4)) : + sawyercoding_decode_sc4(buffer, decodedBuffer, length, sizeof(rct1_s4)); if (decodedLength == sizeof(rct1_s4)) { memcpy(s4, decodedBuffer, sizeof(rct1_s4)); success = true; @@ -65,7 +65,7 @@ bool rct1_read_sv4(const char *path, rct1_s4 *s4) } decodedBuffer = malloc(sizeof(rct1_s4)); - decodedLength = sawyercoding_decode_sv4(buffer, decodedBuffer, length); + decodedLength = sawyercoding_decode_sv4(buffer, decodedBuffer, length, sizeof(rct1_s4)); if (decodedLength == sizeof(rct1_s4)) { memcpy(s4, decodedBuffer, sizeof(rct1_s4)); success = true; diff --git a/src/util/sawyercoding.c b/src/util/sawyercoding.c index c33f1d8c2c..89eaf9e658 100644 --- a/src/util/sawyercoding.c +++ b/src/util/sawyercoding.c @@ -262,20 +262,20 @@ size_t sawyercoding_write_chunk_buffer(uint8 *dst_file, uint8* buffer, sawyercod return chunkHeader.length + sizeof(sawyercoding_chunk_header); } -size_t sawyercoding_decode_sv4(const uint8 *src, uint8 *dst, size_t length) +size_t sawyercoding_decode_sv4(const uint8 *src, uint8 *dst, size_t length, size_t bufferLength) { // (0 to length - 4): RLE chunk // (length - 4 to length): checksum - return decode_chunk_rle(src, dst, length - 4); + return decode_chunk_rle_with_size(src, dst, length - 4, bufferLength); } -size_t sawyercoding_decode_sc4(const uint8 *src, uint8 *dst, size_t length) +size_t sawyercoding_decode_sc4(const uint8 *src, uint8 *dst, size_t length, size_t bufferLength) { size_t decodedLength, i; uint32 *code; // Uncompress - decodedLength = decode_chunk_rle(src, dst, length - 4); + decodedLength = decode_chunk_rle_with_size(src, dst, length - 4, bufferLength); // Decode for (i = 0x60018; i <= min(decodedLength - 1, 0x1F8353); i++) diff --git a/src/util/sawyercoding.h b/src/util/sawyercoding.h index d7bd3d07b2..5926ca054a 100644 --- a/src/util/sawyercoding.h +++ b/src/util/sawyercoding.h @@ -54,8 +54,8 @@ bool sawyercoding_skip_chunk(SDL_RWops *rw); size_t sawyercoding_read_chunk(SDL_RWops* rw, uint8 *buffer); size_t sawyercoding_read_chunk_with_size(SDL_RWops* rw, uint8 *buffer, const size_t buffer_size); size_t sawyercoding_write_chunk_buffer(uint8 *dst_file, uint8* buffer, sawyercoding_chunk_header chunkHeader); -size_t sawyercoding_decode_sv4(const uint8 *src, uint8 *dst, size_t length); -size_t sawyercoding_decode_sc4(const uint8 *src, uint8 *dst, size_t length); +size_t sawyercoding_decode_sv4(const uint8 *src, uint8 *dst, size_t length, size_t bufferLength); +size_t sawyercoding_decode_sc4(const uint8 *src, uint8 *dst, size_t length, size_t bufferLength); size_t sawyercoding_encode_sv4(const uint8 *src, uint8 *dst, size_t length); size_t sawyercoding_decode_td6(const uint8 *src, uint8 *dst, size_t length); size_t sawyercoding_encode_td6(const uint8 *src, uint8 *dst, size_t length);