From 11e78cada516c1c04e0062c6c18fa14dc1559a21 Mon Sep 17 00:00:00 2001 From: Alexander Egorenkov Date: Tue, 19 Jan 2021 09:35:58 +0100 Subject: [PATCH] zdump: catch attempts to seek past end of file in zg_seek() MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Make zg_seek() more robust. Signed-off-by: Alexander Egorenkov Reviewed-by: Philipp Rudo Signed-off-by: Jan Höppner --- zdump/zg.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/zdump/zg.c b/zdump/zg.c index 378cbf9b..8f417936 100644 --- a/zdump/zg.c +++ b/zdump/zg.c @@ -280,6 +280,9 @@ off_t zg_seek(struct zg_fh *zg_fh, off_t off, enum zg_check check) { off_t rc; + if (off >= zg_fh->sb.st_size) + ERR_EXIT("Trying to seek past file end \"%s\"", zg_fh->path); + rc = lseek(zg_fh->fh, off, SEEK_SET); if (rc == -1 && check != ZG_CHECK_NONE) ERR_EXIT_ERRNO("Could not seek \"%s\"", zg_fh->path);