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)
{
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;