From: Ibragimov Rinat Subject: Fix longlink UTF-8 support in KTar Bug: http://bugs.kde.org/show_bug.cgi?id=266141 Bug-Debian: http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=612675 Last-Update: 2011-06-14 Forwarded: yes Origin: other, http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=612675#5 Acked-By: Modestas Vainius tar archives have to use "longlink trick" to store names longer than 100 bytes. KTar class has functions implementing longlink, but they check name length in _characters_, not in bytes. For non-ASCII characters in UTF-8 length of string in bytes and length in characters do not match. In my case file had character-length less than 100 and byte-length greater than 100, so name simply truncated. Such behavior can be observed on non-ASCII UTF-8 or any other multibyte encoding. If file name is very long, resulting .tar may become unreadable. --- a/kdecore/io/ktar.cpp +++ b/kdecore/io/ktar.cpp @@ -745,7 +745,7 @@ bool KTar::doPrepareWriting(const QStrin const QByteArray gname = group.toLocal8Bit(); // If more than 100 chars, we need to use the LongLink trick - if ( fileName.length() > 99 ) + if ( encodedFileName.length() > 99 ) d->writeLonglink(buffer,encodedFileName,'L',uname,gname); // Write (potentially truncated) name @@ -798,7 +798,7 @@ bool KTar::doWriteDir(const QString &nam QByteArray gname = group.toLocal8Bit(); // If more than 100 chars, we need to use the LongLink trick - if ( dirName.length() > 99 ) + if ( encodedDirname.length() > 99 ) d->writeLonglink(buffer,encodedDirname,'L',uname,gname); // Write (potentially truncated) name @@ -850,9 +850,9 @@ bool KTar::doWriteSymLink(const QString QByteArray gname = group.toLocal8Bit(); // If more than 100 chars, we need to use the LongLink trick - if (target.length() > 99) + if (encodedTarget.length() > 99) d->writeLonglink(buffer,encodedTarget,'K',uname,gname); - if ( fileName.length() > 99 ) + if ( encodedFileName.length() > 99 ) d->writeLonglink(buffer,encodedFileName,'L',uname,gname); // Write (potentially truncated) name