From 0c7601c8310192cd1d3a62a7d5ab476db312ca3d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20T=C5=AFma?= Date: Sun, 26 Mar 2017 18:08:37 +0200 Subject: [PATCH] Fixed TAR parser --- src/tar.cpp | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/src/tar.cpp b/src/tar.cpp index f4346e0b..b7a18dbd 100644 --- a/src/tar.cpp +++ b/src/tar.cpp @@ -45,18 +45,23 @@ static quint64 number(const char* data, size_t size) bool Tar::load(const QString &path) { - struct Header hdr; + char buffer[BLOCKSIZE]; + struct Header *hdr = (struct Header*)&buffer; quint64 size; + qint64 ret; _file.setFileName(path); if (!_file.open(QIODevice::ReadOnly)) return false; - while (_file.read((char*)&hdr, BLOCKSIZE)) { - size = number(hdr.size, sizeof(hdr.size)); + while ((ret = _file.read(buffer, BLOCKSIZE)) > 0) { + if (ret < BLOCKSIZE) + return false; + size = number(hdr->size, sizeof(hdr->size)); if (size) - _index.insert(hdr.name, Info(size, _file.pos())); - _file.seek(_file.pos() + BLOCKCOUNT(size) * BLOCKSIZE); + _index.insert(hdr->name, Info(size, _file.pos())); + if (!_file.seek(_file.pos() + BLOCKCOUNT(size) * BLOCKSIZE)) + return false; } return true;