From cdf1e0bcba5ab54e1b87d3c302ad17279ad5b75a Mon Sep 17 00:00:00 2001 From: apio Date: Wed, 23 Nov 2022 20:56:08 +0100 Subject: [PATCH] Make minitar_read_contents cleaner --- src/tar.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/tar.c b/src/tar.c index ae3863c..f82a389 100644 --- a/src/tar.c +++ b/src/tar.c @@ -141,7 +141,10 @@ size_t minitar_read_contents(struct minitar* mp, struct minitar_entry* entry, ch // Move to the position stored in the entry if (fsetpos(mp->stream, &entry->position)) return 0; - size_t nread = fread(buf, 1, max > entry->metadata.size ? entry->metadata.size : max, mp->stream); + // We refuse to read more than the size indicated by the archive + if (max > entry->metadata.size) max = entry->metadata.size; + + size_t nread = fread(buf, 1, max, mp->stream); if (ferror(mp->stream)) return 0; // Restore the current position