diff --git a/autotests/karchivetest.h b/autotests/karchivetest.h --- a/autotests/karchivetest.h +++ b/autotests/karchivetest.h @@ -77,6 +77,8 @@ void testTarRootDir(); void testTarDirectoryTwice(); void testTarIgnoreRelativePathOutsideArchive(); + void testTarLongNonASCIINames(); + void testTarShortNonASCIINames(); void testCreateZip(); void testCreateZipError(); diff --git a/autotests/karchivetest.cpp b/autotests/karchivetest.cpp --- a/autotests/karchivetest.cpp +++ b/autotests/karchivetest.cpp @@ -769,6 +769,55 @@ QCOMPARE(listing.count(), 10); } +void KArchiveTest::testTarLongNonASCIINames() // bug 266141 +{ + const QString tarName = QString("karchive-long-non-ascii-names.tar"); + const QString longName = + QString("раз-два-три-четыре-пять-вышел-зайчик-погулять-вдруг-охотник-" + "выбегает-прямо-в-зайчика.txt"); + + { + KTar tar(tarName); + QVERIFY(tar.open(QIODevice::WriteOnly)); + QVERIFY(tar.writeFile(longName, "", 0644, "user", "users")); + QVERIFY(tar.close()); + } + + { + KTar tar(tarName); + + QVERIFY(tar.open(QIODevice::ReadOnly)); + const KArchiveDirectory *dir = tar.directory(); + QVERIFY(dir != nullptr); + + const QStringList listing = recursiveListEntries(dir, QString(""), 0); + + const QString expectedListingEntry = + QString("mode=644 path=") + longName + QString(" type=file size=0"); + + QCOMPARE(listing.count(), 1); + + QCOMPARE(listing[0], expectedListingEntry); + QVERIFY(tar.close()); + } +} + +void KArchiveTest::testTarShortNonASCIINames() // bug 266141 +{ + KTar tar(QFINDTESTDATA(QString("tar_non_ascii_file_name.tar.gz"))); + + QVERIFY(tar.open(QIODevice::ReadOnly)); + const KArchiveDirectory *dir = tar.directory(); + QVERIFY(dir != nullptr); + + const QStringList listing = recursiveListEntries(dir, QString(""), 0); + + QCOMPARE(listing.count(), 1); + QCOMPARE(listing[0], QString("mode=644 path=абвгдеёжзийклмнопрстуфхцчшщъыьэюя.txt" + " type=file size=0")); + QVERIFY(tar.close()); +} + void KArchiveTest::testTarDirectoryTwice() // bug 206994 { KTar tar(QFINDTESTDATA(QLatin1String("tar_directory_twice.tar.gz"))); diff --git a/autotests/tar_non_ascii_file_name.tar.gz b/autotests/tar_non_ascii_file_name.tar.gz new file mode 100644 index 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000 GIT binary patch literal 0 Hc$@(buffer[j]); } // adjust checksum to count the checksum fields as blanks for (uint j = 0; j < 8 /*size of the checksum field including the \0 and the space*/; j++) { - check -= buffer[148 + j]; + check -= static_cast(buffer[148 + j]); } check += 8 * ' '; @@ -698,7 +698,7 @@ // Header check sum int check = 32; for (uint j = 0; j < 0x200; ++j) { - check += buffer[j]; + check += static_cast(buffer[j]); } s = QByteArray::number(check, 8); // octal s = s.rightJustified(6, '0'); @@ -773,8 +773,8 @@ const QByteArray uname = user.toLocal8Bit(); const QByteArray gname = group.toLocal8Bit(); - // If more than 100 chars, we need to use the LongLink trick - if (fileName.length() > 99) { + // If more than 100 bytes, we need to use the LongLink trick + if (encodedFileName.length() > 99) { d->writeLonglink(buffer, encodedFileName, 'L', uname.constData(), gname.constData()); } @@ -838,8 +838,8 @@ QByteArray uname = user.toLocal8Bit(); QByteArray gname = group.toLocal8Bit(); - // If more than 100 chars, we need to use the LongLink trick - if (dirName.length() > 99) { + // If more than 100 bytes, we need to use the LongLink trick + if (encodedDirname.length() > 99) { d->writeLonglink(buffer, encodedDirname, 'L', uname.constData(), gname.constData()); } @@ -894,11 +894,11 @@ QByteArray uname = user.toLocal8Bit(); QByteArray gname = group.toLocal8Bit(); - // If more than 100 chars, we need to use the LongLink trick - if (target.length() > 99) { + // If more than 100 bytes, we need to use the LongLink trick + if (encodedTarget.length() > 99) { d->writeLonglink(buffer, encodedTarget, 'K', uname.constData(), gname.constData()); } - if (fileName.length() > 99) { + if (encodedFileName.length() > 99) { d->writeLonglink(buffer, encodedFileName, 'L', uname.constData(), gname.constData()); }