Verify sv4/sc4 sizes when loading them

This commit is contained in:
Michał Janiszewski 2016-09-01 06:59:12 +00:00 committed by Gymnasiast
parent 355b33ba94
commit f3fe28e722
3 changed files with 9 additions and 9 deletions

View File

@ -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;

View File

@ -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++)

View File

@ -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);