1
0
mirror of https://github.com/tumic0/GPXSee.git synced 2025-01-18 11:52:08 +01:00

Fixed TAR parser

This commit is contained in:
Martin Tůma 2017-03-26 18:08:37 +02:00
parent 19eb3fba7f
commit 0c7601c831

View File

@ -45,18 +45,23 @@ static quint64 number(const char* data, size_t size)
bool Tar::load(const QString &path) bool Tar::load(const QString &path)
{ {
struct Header hdr; char buffer[BLOCKSIZE];
struct Header *hdr = (struct Header*)&buffer;
quint64 size; quint64 size;
qint64 ret;
_file.setFileName(path); _file.setFileName(path);
if (!_file.open(QIODevice::ReadOnly)) if (!_file.open(QIODevice::ReadOnly))
return false; return false;
while (_file.read((char*)&hdr, BLOCKSIZE)) { while ((ret = _file.read(buffer, BLOCKSIZE)) > 0) {
size = number(hdr.size, sizeof(hdr.size)); if (ret < BLOCKSIZE)
return false;
size = number(hdr->size, sizeof(hdr->size));
if (size) if (size)
_index.insert(hdr.name, Info(size, _file.pos())); _index.insert(hdr->name, Info(size, _file.pos()));
_file.seek(_file.pos() + BLOCKCOUNT(size) * BLOCKSIZE); if (!_file.seek(_file.pos() + BLOCKCOUNT(size) * BLOCKSIZE))
return false;
} }
return true; return true;