From c69a2f6d19117670060c07632a3f4e6f7a2dc880 Mon Sep 17 00:00:00 2001 From: alqualos Date: Wed, 23 Jul 2014 18:55:00 +0000 Subject: [PATCH] Test for "large" files (faked, but seemingly working) --- quazip/quazip/unzip.c | 46 +++++++------- quazip/qztest/testquazipfile.cpp | 105 +++++++++++++++++++++++++++++++ quazip/qztest/testquazipfile.h | 1 + 3 files changed, 129 insertions(+), 23 deletions(-) diff --git a/quazip/quazip/unzip.c b/quazip/quazip/unzip.c index 89405ae..3221808 100644 --- a/quazip/quazip/unzip.c +++ b/quazip/quazip/unzip.c @@ -1048,33 +1048,33 @@ local int unz64local_GetCurrentFileInfoInternal (unzFile file, /* ZIP64 extra fields */ if (headerId == 0x0001) { - uLong uL; + uLong uL; - if(file_info.uncompressed_size == (ZPOS64_T)(unsigned long)-1) - { - if (unz64local_getLong64(&s->z_filefunc, s->filestream,&file_info.uncompressed_size) != UNZ_OK) - err=UNZ_ERRNO; - } + if(file_info.uncompressed_size == (ZPOS64_T)(unsigned long)-1) + { + if (unz64local_getLong64(&s->z_filefunc, s->filestream,&file_info.uncompressed_size) != UNZ_OK) + err=UNZ_ERRNO; + } - if(file_info.compressed_size == (ZPOS64_T)(unsigned long)-1) - { - if (unz64local_getLong64(&s->z_filefunc, s->filestream,&file_info.compressed_size) != UNZ_OK) - err=UNZ_ERRNO; - } + if(file_info.compressed_size == (ZPOS64_T)(unsigned long)-1) + { + if (unz64local_getLong64(&s->z_filefunc, s->filestream,&file_info.compressed_size) != UNZ_OK) + err=UNZ_ERRNO; + } - if(file_info_internal.offset_curfile == (ZPOS64_T)(unsigned long)-1) - { - /* Relative Header offset */ - if (unz64local_getLong64(&s->z_filefunc, s->filestream,&file_info_internal.offset_curfile) != UNZ_OK) - err=UNZ_ERRNO; - } + if(file_info_internal.offset_curfile == (ZPOS64_T)(unsigned long)-1) + { + /* Relative Header offset */ + if (unz64local_getLong64(&s->z_filefunc, s->filestream,&file_info_internal.offset_curfile) != UNZ_OK) + err=UNZ_ERRNO; + } - if(file_info.disk_num_start == (unsigned long)-1) - { - /* Disk Start Number */ - if (unz64local_getLong(&s->z_filefunc, s->filestream,&uL) != UNZ_OK) - err=UNZ_ERRNO; - } + if(file_info.disk_num_start == (unsigned long)-1) + { + /* Disk Start Number */ + if (unz64local_getLong(&s->z_filefunc, s->filestream,&uL) != UNZ_OK) + err=UNZ_ERRNO; + } } else diff --git a/quazip/qztest/testquazipfile.cpp b/quazip/qztest/testquazipfile.cpp index ba1c5fe..692282f 100644 --- a/quazip/qztest/testquazipfile.cpp +++ b/quazip/qztest/testquazipfile.cpp @@ -405,3 +405,108 @@ void TestQuaZipFile::setFileAttrs() removeTestFiles(fileNames); QDir().remove(testZip.getZipName()); } + +void TestQuaZipFile::largeFile() +{ + QDir curDir; + QVERIFY(curDir.mkpath("tmp")); + QFile fakeLargeFile("tmp/large.zip"); + QVERIFY(fakeLargeFile.open(QIODevice::WriteOnly)); + QDataStream ds(&fakeLargeFile); + ds.setByteOrder(QDataStream::LittleEndian); + QList localOffsets; + const int numFiles = 2; // name fixed to 5 bytes, so MAX 10 FILES!!! + for (int i = 0; i < numFiles; ++i) { + localOffsets.append(fakeLargeFile.pos()); + QBuffer extra; + extra.open(QIODevice::WriteOnly); + QDataStream es(&extra); + es.setByteOrder(QDataStream::LittleEndian); + // prepare extra + es << static_cast(0x0001u); // zip64 + es << static_cast(16); // extra data size + es << static_cast(0); // uncompressed size + es << static_cast(0); // compressed size + // now the local header + ds << static_cast(0x04034b50u); // local magic + ds << static_cast(45); // version needed + ds << static_cast(0); // flags + ds << static_cast(0); // method + ds << static_cast(0); // time 00:00:00 + ds << static_cast(0x21); // date 1980-01-01 + ds << static_cast(0); // CRC-32 + ds << static_cast(0xFFFFFFFFu); // compressed size + ds << static_cast(0xFFFFFFFFu); // uncompressed size + ds << static_cast(5); // name length + ds << static_cast(extra.size()); // extra length + ds.writeRawData("file", 4); // name + ds << static_cast('0' + i); // name (contd.) + ds.writeRawData(extra.buffer(), extra.size()); + } + // central dir: + qint64 centralStart = fakeLargeFile.pos(); + for (int i = 0; i < numFiles; ++i) { + QBuffer extra; + extra.open(QIODevice::WriteOnly); + QDataStream es(&extra); + es.setByteOrder(QDataStream::LittleEndian); + // prepare extra + es << static_cast(0x0001u); // zip64 + es << static_cast(24); // extra data size + es << static_cast(0); // uncompressed size + es << static_cast(0); // compressed size + es << static_cast(localOffsets[i]); + // now the central dir header + ds << static_cast(0x02014b50u); // central magic + ds << static_cast(45); // version made by + ds << static_cast(45); // version needed + ds << static_cast(0); // flags + ds << static_cast(0); // method + ds << static_cast(0); // time 00:00:00 + ds << static_cast(0x21); // date 1980-01-01 + ds << static_cast(0); // CRC-32 + ds << static_cast(0xFFFFFFFFu); // compressed size + ds << static_cast(0xFFFFFFFFu); // uncompressed size + ds << static_cast(5); // name length + ds << static_cast(extra.size()); // extra length + ds << static_cast(0); // comment length + ds << static_cast(0); // disk number + ds << static_cast(0); // internal attrs + ds << static_cast(0); // external attrs + ds << static_cast(0xFFFFFFFFu); // local offset + ds.writeRawData("file", 4); // name + ds << static_cast('0' + i); // name (contd.) + ds.writeRawData(extra.buffer(), extra.size()); + } + qint64 centralEnd = fakeLargeFile.pos(); + // zip64 end + ds << static_cast(0x06064b50); // zip64 end magic + ds << static_cast(44); // size of the zip64 end + ds << static_cast(45); // version made by + ds << static_cast(45); // version needed + ds << static_cast(0); // disk number + ds << static_cast(0); // central dir disk number + ds << static_cast(2); // number of entries on disk + ds << static_cast(2); // total number of entries + ds << static_cast(centralEnd - centralStart); // size + ds << static_cast(centralStart); // offset + // zip64 locator + ds << static_cast(0x07064b50); // zip64 locator magic + ds << static_cast(0); // disk number + ds << static_cast(centralEnd); // offset + ds << static_cast(1); // number of disks + // zip32 end + ds << static_cast(0x06054b50); // end magic + ds << static_cast(0); // disk number + ds << static_cast(0); // central dir disk number + ds << static_cast(2); // number of entries + ds << static_cast(0xFFFFFFFFu); // central dir size + ds << static_cast(0xFFFFFFFFu); // central dir offset + ds << static_cast(0); // comment length + fakeLargeFile.close(); + QuaZip fakeLargeZip("tmp/large.zip"); + QVERIFY(fakeLargeZip.open(QuaZip::mdUnzip)); + QCOMPARE(fakeLargeZip.getFileInfoList().size(), numFiles); + QCOMPARE(fakeLargeZip.getFileInfoList()[0].uncompressedSize, + static_cast(0)); +} diff --git a/quazip/qztest/testquazipfile.h b/quazip/qztest/testquazipfile.h index dc74832..c00c0f8 100644 --- a/quazip/qztest/testquazipfile.h +++ b/quazip/qztest/testquazipfile.h @@ -45,6 +45,7 @@ private slots: void setFileName(); void constructorDestructor(); void setFileAttrs(); + void largeFile(); }; #endif // QUAZIP_TEST_QUAZIPFILE_H