Bug 56682 - KZip produces invalid ZIP files
Summary: KZip produces invalid ZIP files
Status: CLOSED FIXED
Alias: None
Product: kio
Classification: Frameworks and Libraries
Component: general (show other bugs)
Version: unspecified
Platform: Compiled Sources Linux
: NOR normal
Target Milestone: ---
Assignee: David Faure
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2003-04-01 02:20 UTC by Nicolas Goutte
Modified: 2003-10-30 01:30 UTC (History)
0 users

See Also:
Latest Commit:
Version Fixed In:


Attachments
Error returning by zip (158 bytes, text/plain)
2003-04-01 02:22 UTC, Nicolas Goutte
Details
kzip_cpp.diff (deleted)
2003-04-02 18:51 UTC, Nicolas Goutte
Details
Patch (807 bytes, patch)
2003-04-02 18:51 UTC, Nicolas Goutte
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Nicolas Goutte 2003-04-01 02:20:11 UTC
Version:            (using KDE KDE 3.1)
Installed from:    Compiled From Sources
Compiler:          gcc 3.2 -march=pentium2
OS:          Linux

KZip produces files where the program zip refuses to add anything to them. (The program unzip works.)

This is in KDE_3_1_BRANCH (even last revision) and probably in CVS HEAD too.

The problem is that in KZip::closeArchive the code is:

        if ( it.current()->encoding() == 8 )
        {
            buffer[ 8 ] = 8, // general purpose bit flag, deflated
            buffer[ 10 ] = 8; // compression method, deflated
        }

But in KZip::prepareWriting the code is:
    buffer[ 8 ] = char(e->encoding()); // compression method
    buffer[ 9 ] = char(e->encoding() >> 8);

Zip complains that these too entries are different. I suppose that the code in KZip::closeArchive is correct, but the ZIP specification should be checked.

Have a nice day/evening/night!
Comment 1 Nicolas Goutte 2003-04-01 02:22:14 UTC
Created attachment 1281 [details]
Error returning by zip

The error can be created by saving an empty KWord file as test.kwd
Then:
  touch test
  zip test.kwd test
This gives the error.
Comment 2 Nicolas Goutte 2003-04-02 16:07:12 UTC
Subject:  New: KZip produces invalid ZIP files

Attached is a patch for kdelibs/kio/kio/kzip.cpp (KDE_3_1_BRANCH)

The problem seems that the general purpose bit flag needs to be NULL, even at 
the 4th bit. If the 5th bit is set, zip seems to want extra data, which we do 
not have/give.

I have checked that KWord saves and load, zip can add a new file, unzip works. 
(However kziptest seems to fail.)

Someone would need to port this to KDE CVS HEAD.

Have a nice day/evening/night!

Created an attachment (id=1292)
kzip_cpp.diff
Comment 3 Nicolas Goutte 2003-04-02 16:13:37 UTC
Subject:  New: KZip produces invalid ZIP files

I have made an error and now kziptest (readwrite) works correctly.

(I was runnig kziptest KDE 3.1.x against KDE 3.0 (as I was running KMail))

Have a nice day/evening/night!

Comment 4 David Faure 2003-04-02 18:33:49 UTC
Subject: Re:  KZip produces invalid ZIP files

On Wednesday 02 April 2003 16:07, you wrote:
>  --> (http://bugs.kde.org/attachment.cgi?id=1292&action=view)

I'm afraid this attachment is empty.

Does this mean Holger's first patch works?
Feel free to commit once it works for you, anyway.

Comment 5 Nicolas Goutte 2003-04-02 18:51:37 UTC
Created attachment 1293 [details]
Patch
Comment 6 Nicolas Goutte 2003-04-02 18:55:03 UTC
(Now I have uploaded the patch instead of mailing it.) 
 
No, Holger's patch is wrong. 
 
What needs to be done is exactly the opposite of what I thought first. 
 
Have a nice day/evening/night! 
Comment 7 David Faure 2003-04-02 18:59:37 UTC
Subject: Re:  KZip produces invalid ZIP files

On Wednesday 02 April 2003 18:55, you wrote:
> What needs to be done is exactly the opposite of what I thought first. 

Ah ok. Well I can't help here. Either commit or mail Holger...

Comment 8 Nicolas Goutte 2003-04-02 19:43:52 UTC
Subject: Re:  New: KZip produces invalid ZIP files

Good, now I think that I understand better the problem.

I looked at bit 4 but 8=2^3. But bit 3 is the variant that put zero to sies 
and CRC and gives these sizes in an extra local header at the end of the file 
data.

So if I remember well, we do not write in these mode. So my patch should be 
right (and now I understand why and the reason of zip reactions.)

I am going to commit.

Have a nice day/evening/night!


On Wednesday 02 April 2003 16:08, Nicolas Goutte wrote:
> Attached is a patch for kdelibs/kio/kio/kzip.cpp (KDE_3_1_BRANCH)
>
> The problem seems that the general purpose bit flag needs to be NULL, even
> at the 4th bit. If the 5th bit is set, zip seems to want extra data, which
> we do not have/give.
>
> I have checked that KWord saves and load, zip can add a new file, unzip
> works. (However kziptest seems to fail.)
>
> Someone would need to port this to KDE CVS HEAD.
>
> Have a nice day/evening/night!

Comment 9 Nicolas Goutte 2003-04-02 19:44:31 UTC
Subject: KDE_3_1_BRANCH: kdelibs/kio/kio

CVS commit by goutte: 

Write out correctly ZIP's general purpose bit flag
(We write the sizes and the CRC directly in the local header. We do not need
to tell that we are "delaying" this information.)
CCMAIL:56682@bugs.kde.org


  M +3 -5      kzip.cpp   1.20.2.3


--- kdelibs/kio/kio/kzip.cpp  #1.20.2.2:1.20.2.3
@@ -461,9 +461,7 @@ bool KZip::closeArchive()
         qmemmove(buffer, head, sizeof(head));
 
-        if ( it.current()->encoding() == 8 )
-        {
-            buffer[ 8 ] = 8, // general purpose bit flag, deflated
-            buffer[ 10 ] = 8; // compression method, deflated
-        }
+        buffer[ 10 ] = char(it.current()->encoding()); // compression method
+        buffer[ 11 ] = char(it.current()->encoding() >> 8);
+
 
         transformToMsDos( it.current()->datetime(), &buffer[ 12 ] );


Comment 10 Nicolas Goutte 2003-04-02 19:50:48 UTC
Subject: kdelibs/kio/kio

CVS commit by goutte: 

Write out correctly the general purpose bit flag
(We are writing the sizes and the CRC in the local header and not at the end
of each file. (Bit 3))
(Forward-port, not tested)
CCMAIL:56682-close@bugs.kde.org


  M +3 -6      kzip.cpp   1.32


--- kdelibs/kio/kio/kzip.cpp  #1.31:1.32
@@ -724,9 +724,6 @@ bool KZip::closeArchive()
         qmemmove(buffer, head, sizeof(head));
 
-        if ( it.current()->encoding() == 8 )
-        {
-            buffer[ 8 ] = 8, // general purpose bit flag, deflated
-            buffer[ 10 ] = 8; // compression method, deflated
-        }
+        buffer[ 10 ] = char(it.current()->encoding()); // compression method
+        buffer[ 11 ] = char(it.current()->encoding() >> 8);
 
         transformToMsDos( it.current()->datetime(), &buffer[ 12 ] );