Skip to content

Commit

Permalink
Replace assertions in DecodeChunkRLEWithSize() (#22061)
Browse files Browse the repository at this point in the history
  • Loading branch information
Gymnasiast committed May 19, 2024
1 parent 2217d40 commit eaba5f3
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 deletions src/openrct2/util/SawyerCoding.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -219,8 +219,9 @@ static size_t DecodeChunkRLEWithSize(const uint8_t* src_buffer, uint8_t* dst_buf

dst = dst_buffer;

assert(length > 0);
assert(dstSize > 0);
if (length <= 0 || dstSize <= 0)
throw std::out_of_range("Invalid RLE string!");

for (size_t i = 0; i < length; i++)
{
rleCodeByte = src_buffer[i];
Expand All @@ -235,8 +236,8 @@ static size_t DecodeChunkRLEWithSize(const uint8_t* src_buffer, uint8_t* dst_buf
}
else
{
assert(dst + rleCodeByte + 1 <= dst_buffer + dstSize);
assert(i + 1 < length);
if ((dst + rleCodeByte + 1 > dst_buffer + dstSize) || (i + 1 >= length))
throw std::out_of_range("Invalid RLE string!");
std::memcpy(dst, src_buffer + i + 1, rleCodeByte + 1);
dst = reinterpret_cast<uint8_t*>(reinterpret_cast<uintptr_t>(dst) + rleCodeByte + 1);
i += rleCodeByte + 1;
Expand Down

0 comments on commit eaba5f3

Please sign in to comment.