From 2eec954d10396fba1755261f3d911701818755d8 Mon Sep 17 00:00:00 2001 From: David Oberhollenzer Date: Tue, 10 Oct 2023 19:07:26 +0200 Subject: libsqfs: Rework the buffer advance logic for sqfs_istream_t Remove the asserts. If we eat more data than present, reset the offset and count to zero. Signed-off-by: David Oberhollenzer --- lib/sqfs/src/io/istream.c | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/lib/sqfs/src/io/istream.c b/lib/sqfs/src/io/istream.c index 7e1b896..6b9388f 100644 --- a/lib/sqfs/src/io/istream.c +++ b/lib/sqfs/src/io/istream.c @@ -113,11 +113,12 @@ static void file_advance_buffer(sqfs_istream_t *strm, size_t count) { file_istream_t *file = (file_istream_t *)strm; - assert(count <= file->buffer_used); - - file->buffer_offset += count; - - assert(file->buffer_offset <= file->buffer_used); + if (count < (file->buffer_used - file->buffer_offset)) { + file->buffer_offset += count; + } else { + file->buffer_offset = 0; + file->buffer_used = 0; + } } static const char *file_get_filename(sqfs_istream_t *strm) -- cgit v1.2.3