From c3918838f68f5112fadf3f3a2cc75bb0a3310393 Mon Sep 17 00:00:00 2001 From: Patric Stout Date: Sat, 9 Sep 2023 16:06:00 +0200 Subject: [PATCH] Fix: crash when opening a damaged base-graphics (#11275) --- src/random_access_file.cpp | 5 +++-- src/random_access_file_type.h | 2 +- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/src/random_access_file.cpp b/src/random_access_file.cpp index 60df8cdc00..37f51530df 100644 --- a/src/random_access_file.cpp +++ b/src/random_access_file.cpp @@ -146,9 +146,10 @@ void RandomAccessFile::ReadBlock(void *ptr, size_t size) * Skip \a n bytes ahead in the file. * @param n Number of bytes to skip reading. */ -void RandomAccessFile::SkipBytes(int n) +void RandomAccessFile::SkipBytes(size_t n) { - int remaining = this->buffer_end - this->buffer; + assert(this->buffer_end >= this->buffer); + size_t remaining = this->buffer_end - this->buffer; if (n <= remaining) { this->buffer += n; } else { diff --git a/src/random_access_file_type.h b/src/random_access_file_type.h index 1573855274..caf58a9ba8 100644 --- a/src/random_access_file_type.h +++ b/src/random_access_file_type.h @@ -51,7 +51,7 @@ public: uint32_t ReadDword(); void ReadBlock(void *ptr, size_t size); - void SkipBytes(int n); + void SkipBytes(size_t n); }; #endif /* RANDOM_ACCESS_FILE_TYPE_H */