From 2b29f252e53ef6e75ec1d309cf539ad1a63c252d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20Janiszewski?= Date: Sat, 16 Jan 2016 00:18:21 +0100 Subject: [PATCH 1/2] Assert for evergreen gardens --- src/util/sawyercoding.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/util/sawyercoding.c b/src/util/sawyercoding.c index d73bda1fda..ec2196e7b5 100644 --- a/src/util/sawyercoding.c +++ b/src/util/sawyercoding.c @@ -21,6 +21,7 @@ #include "../addresses.h" #include "../platform/platform.h" #include "sawyercoding.h" +#include "../scenario.h" static size_t decode_chunk_rle(const uint8* src_buffer, uint8* dst_buffer, size_t length); static size_t decode_chunk_repeat(uint8 *buffer, size_t length); @@ -418,6 +419,8 @@ static size_t encode_chunk_repeat(const uint8 *src_buffer, uint8 *dst_buffer, si repeatCount = 0; maxRepeatCount = min(7, searchEnd - repeatIndex); for (j = 0; j <= maxRepeatCount; j++) { + assert(repeatIndex + j < sizeof(rct_s6_data) - offsetof(rct_s6_data, dword_010E63B8)); + assert(i + j < sizeof(rct_s6_data) - offsetof(rct_s6_data, dword_010E63B8)); if (src_buffer[repeatIndex + j] == src_buffer[i + j]) { repeatCount++; } else { From f35fac6030ade2e33f538e2fb82ee915f125f05d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20Janiszewski?= Date: Sat, 16 Jan 2016 18:10:44 +0100 Subject: [PATCH 2/2] Update assert condition --- src/util/sawyercoding.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/util/sawyercoding.c b/src/util/sawyercoding.c index ec2196e7b5..4ae6edc537 100644 --- a/src/util/sawyercoding.c +++ b/src/util/sawyercoding.c @@ -419,8 +419,8 @@ static size_t encode_chunk_repeat(const uint8 *src_buffer, uint8 *dst_buffer, si repeatCount = 0; maxRepeatCount = min(7, searchEnd - repeatIndex); for (j = 0; j <= maxRepeatCount; j++) { - assert(repeatIndex + j < sizeof(rct_s6_data) - offsetof(rct_s6_data, dword_010E63B8)); - assert(i + j < sizeof(rct_s6_data) - offsetof(rct_s6_data, dword_010E63B8)); + assert(repeatIndex + j < length); + assert(i + j < length); if (src_buffer[repeatIndex + j] == src_buffer[i + j]) { repeatCount++; } else {