Test for "large" files (faked, but seemingly working)
This commit is contained in:
parent
b8726ee5c9
commit
c69a2f6d19
3 changed files with 129 additions and 23 deletions
|
@ -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
|
||||
|
|
|
@ -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<qint64> 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<quint16>(0x0001u); // zip64
|
||||
es << static_cast<quint16>(16); // extra data size
|
||||
es << static_cast<quint64>(0); // uncompressed size
|
||||
es << static_cast<quint64>(0); // compressed size
|
||||
// now the local header
|
||||
ds << static_cast<quint32>(0x04034b50u); // local magic
|
||||
ds << static_cast<quint16>(45); // version needed
|
||||
ds << static_cast<quint16>(0); // flags
|
||||
ds << static_cast<quint16>(0); // method
|
||||
ds << static_cast<quint16>(0); // time 00:00:00
|
||||
ds << static_cast<quint16>(0x21); // date 1980-01-01
|
||||
ds << static_cast<quint32>(0); // CRC-32
|
||||
ds << static_cast<quint32>(0xFFFFFFFFu); // compressed size
|
||||
ds << static_cast<quint32>(0xFFFFFFFFu); // uncompressed size
|
||||
ds << static_cast<quint16>(5); // name length
|
||||
ds << static_cast<quint16>(extra.size()); // extra length
|
||||
ds.writeRawData("file", 4); // name
|
||||
ds << static_cast<qint8>('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<quint16>(0x0001u); // zip64
|
||||
es << static_cast<quint16>(24); // extra data size
|
||||
es << static_cast<quint64>(0); // uncompressed size
|
||||
es << static_cast<quint64>(0); // compressed size
|
||||
es << static_cast<quint64>(localOffsets[i]);
|
||||
// now the central dir header
|
||||
ds << static_cast<quint32>(0x02014b50u); // central magic
|
||||
ds << static_cast<quint16>(45); // version made by
|
||||
ds << static_cast<quint16>(45); // version needed
|
||||
ds << static_cast<quint16>(0); // flags
|
||||
ds << static_cast<quint16>(0); // method
|
||||
ds << static_cast<quint16>(0); // time 00:00:00
|
||||
ds << static_cast<quint16>(0x21); // date 1980-01-01
|
||||
ds << static_cast<quint32>(0); // CRC-32
|
||||
ds << static_cast<quint32>(0xFFFFFFFFu); // compressed size
|
||||
ds << static_cast<quint32>(0xFFFFFFFFu); // uncompressed size
|
||||
ds << static_cast<quint16>(5); // name length
|
||||
ds << static_cast<quint16>(extra.size()); // extra length
|
||||
ds << static_cast<quint16>(0); // comment length
|
||||
ds << static_cast<quint16>(0); // disk number
|
||||
ds << static_cast<quint16>(0); // internal attrs
|
||||
ds << static_cast<quint32>(0); // external attrs
|
||||
ds << static_cast<quint32>(0xFFFFFFFFu); // local offset
|
||||
ds.writeRawData("file", 4); // name
|
||||
ds << static_cast<qint8>('0' + i); // name (contd.)
|
||||
ds.writeRawData(extra.buffer(), extra.size());
|
||||
}
|
||||
qint64 centralEnd = fakeLargeFile.pos();
|
||||
// zip64 end
|
||||
ds << static_cast<quint32>(0x06064b50); // zip64 end magic
|
||||
ds << static_cast<quint64>(44); // size of the zip64 end
|
||||
ds << static_cast<quint16>(45); // version made by
|
||||
ds << static_cast<quint16>(45); // version needed
|
||||
ds << static_cast<quint32>(0); // disk number
|
||||
ds << static_cast<quint32>(0); // central dir disk number
|
||||
ds << static_cast<quint64>(2); // number of entries on disk
|
||||
ds << static_cast<quint64>(2); // total number of entries
|
||||
ds << static_cast<quint64>(centralEnd - centralStart); // size
|
||||
ds << static_cast<quint64>(centralStart); // offset
|
||||
// zip64 locator
|
||||
ds << static_cast<quint32>(0x07064b50); // zip64 locator magic
|
||||
ds << static_cast<quint32>(0); // disk number
|
||||
ds << static_cast<quint64>(centralEnd); // offset
|
||||
ds << static_cast<quint32>(1); // number of disks
|
||||
// zip32 end
|
||||
ds << static_cast<quint32>(0x06054b50); // end magic
|
||||
ds << static_cast<quint16>(0); // disk number
|
||||
ds << static_cast<quint16>(0); // central dir disk number
|
||||
ds << static_cast<quint16>(2); // number of entries
|
||||
ds << static_cast<quint32>(0xFFFFFFFFu); // central dir size
|
||||
ds << static_cast<quint32>(0xFFFFFFFFu); // central dir offset
|
||||
ds << static_cast<quint16>(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<quint32>(0));
|
||||
}
|
||||
|
|
|
@ -45,6 +45,7 @@ private slots:
|
|||
void setFileName();
|
||||
void constructorDestructor();
|
||||
void setFileAttrs();
|
||||
void largeFile();
|
||||
};
|
||||
|
||||
#endif // QUAZIP_TEST_QUAZIPFILE_H
|
||||
|
|
Loading…
Reference in a new issue