SUMMARY data() and size() aren't consistent: the data() contains less bytes than indicated by size() for file 1 in this archive. CODE TO REPRODUCE KZip zip("datalessthansize.zip"); // see below zip.open(QIODevice::ReadOnly); auto dir = zip.directory(); auto dir1 = dir->entry("dir1"); const KArchiveFile *file1 = dir1->file("file1"); const QByteArray data1 = file1->data(); qDebug() << "file1" << file1->position() << file1->size() << data1.size(); const KArchiveFile *file2 = dir1->file("file2"); const QByteArray data2 = file2->data(); qDebug() << "file2" << file2->position() << file2->size() << data2.size(); OBSERVED RESULT position() size() data().size() file1 68 5757690 <= 5750784 ??? file2 5758706 566784 566784 EXPECTED RESULT position() size() data().size() file1 68 5757690 5757690 file2 5758706 566784 566784 SOFTWARE/OS VERSIONS Linux 5.4.90-intel-pk-standard x86_64 Qt Version: 5.15 ADDITIONAL INFORMATION Not seen with 5.30 on x86 platform. Creating the test archive (6MB is too much for an attachment) mkdir dir1 head -c 5757690 < /dev/urandom > dir1/file1 head -c 566784 < /dev/urandom > dir1/file2 zip datalessthansize.zip dir1/file1 dir1/file2
There is even an assert in KArchiveFile::data(): Q_ASSERT(arr.size() == d->size); I am not sure if this is normal behaviour with the zip spec, or a bug on our side (I don't see how, but... ).
Works fine for me in KArchive 5.82 (well when i made your code compile) auto dir1 = dir->entry("dir1"); needs to be auto dir1 = dynamic_cast<const KArchiveDirectory*>(dir->entry("dir1")); Can you please try in something newer?
Apologies for the code error, obviously, that cast is in my code. I've tried the test again with libKF5Archive.so.5.82.0 and it still trigger this bug. Any suggestion on how to diagnose this further? Versions of libz?
Honestly besides you debugging it yourself or providing a 100% scenario where we can reproduce it (docker recipe?) I am not sure what to suggest.
As this KArchive version is built through a Yocto meta layer, I also asked for assistence there: https://github.com/schnitzeltony/meta-qt5-extra/issues/86 I've included a minimal test case which does not depend on randomness. If you would be able to confirm this test runs correctly with a standalone build of KArchive, that would be helpful in determining whether the issue resides in KArchive or the specific configuration inside the Yocto build.
tsdgeos@xps:~/test:$ ./test ********* Start testing of KArchiveTest ********* Config: Using QtTest library 5.15.2, Qt 5.15.2 (x86_64-little_endian-lp64 shared (dynamic) release build; by GCC 11.1.0), arch unknown PASS : KArchiveTest::initTestCase() PASS : KArchiveTest::sizeVsDataDiscrepancy() PASS : KArchiveTest::cleanupTestCase() Totals: 3 passed, 0 failed, 0 skipped, 0 blacklisted, 75ms ********* Finished testing of KArchiveTest *********
Thank you for the confirmation, I'll chase it further on the Yocto meta layer issue and keep you posted.
As we've verified https://github.com/jtkukunas/zlib/issues/33 is the root cause, this issue can be closed. Thank you for the support!
Thanks for the feedback o/