Bugs in nsIZipReader, nsIZipWriter, nsIZipEntry

UNCONFIRMED
Unassigned

Status

()

P5
normal
UNCONFIRMED
7 years ago
a year ago

People

(Reporter: vb4guy, Unassigned)

Tracking

2.0 Branch
x86
Windows XP
Points:
---

Firefox Tracking Flags

(Not tracked)

Details

(Whiteboard: [necko-would-take])

Attachments

(1 attachment)

(Reporter)

Description

7 years ago
User-Agent:       Mozilla/5.0 (compatible; MSIE 9.0; Windows NT 6.1; Trident/5.0)
Build Identifier: Firefox 5 Beta 3

I am looking to imlement the Zip compression methods that are available in XPCOM but there are a few bugs:

1. nsIZipReader.manifestEntriesCount always returns 0 instead the number of entries in the file
2. nsIZipEntry.lastModifiedTime *always* returns an invalid date.
3. nsIZipEntry.compression always returns 8, regardless of the method used in nsIZipWriter.addEntryFile().
4. nsIZipWriter.addEntryDirectory() doesn't put the specified date time modified.
5. nsIZipWriter.open() and nsIZipWriter.open() are unable to open an empty zip file, they return an error saying that the file is corrupted.
6. nsIZipWriter and nsIZipWriter don't appear to support password protected zip files.

FYI, I have been using 7-Zip to verify the items above.

Reproducible: Always
Component: Developer Tools → Networking: JAR
Product: Firefox → Core
QA Contact: developer.tools → networking.jar

Comment 1

7 years ago
I could not reproduce the issue on the latest Nightly:
 Mozilla/5.0 (Windows NT 6.1; rv:7.0a1) Gecko/20110607 Firefox/7.0a1

*Note: If reproducible, could you provide more clear steps to check this issue? Thanks
(Reporter)

Updated

7 years ago
Component: Networking: JAR → XPCOM
OS: Windows 7 → Windows XP
Version: unspecified → 2.0 Branch
(Reporter)

Comment 2

7 years ago
I just installed the latest nightly version and *all* of the issues above still exist.  I will post examples on how to duplicate the issues.
(Reporter)

Comment 3

7 years ago
Below is the script that I used to duplicate the first issue:

Create a zip file called "C:\zip1.zip" and add at least one file to it.
Create a HTML page with the following javascript:

        netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");

        var ZipReader = Components.classes["@mozilla.org/libjar/zip-reader;1"].createInstance(Components.interfaces.nsIZipReader);
        var File = Components.classes["@mozilla.org/file/local;1"].createInstance(Components.interfaces.nsILocalFile);
        File.initWithPath("C:\\zip1.zip");

        var DumpText = "";

        ZipReader.open(File);
        DumpText += "ZipReader.manifestEntriesCount: " + ZipReader.manifestEntriesCount + "<br />";

        ZipReader.close();
        
        document.write(DumpText);
(Reporter)

Comment 4

7 years ago
To duplicate issue #2, create a zip file "C:\zip1.zip" that contain a file "C:\write_test1.txt" and a HTML page with the following script:

        netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");

        var Zip = new Cosmos.Compression.Zip("file://c:\\zip1.zip");
        var File = new Cosmos.IO.LocalFile();
        var ZipItem = null;

        var DumpText = "";

        File.SetUrl("file://c:\\write_test.txt");
        DumpText += "DT (LocalFile): " + File.GetInternalFileObject().lastModifiedTime + "<br />";

        ZipItem = Zip.GetItem("write_test1.txt");
        DumpText += "DT (ZipItem): " + ZipItem.GetZipEntry().lastModifiedTime + "<br />";

        Zip.Close();

        DumpText += "Done." + "<br />";
        document.write(DumpText);
(Reporter)

Comment 5

7 years ago
Sorry, please ignore the last example.  Use the following instead:

        netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");

        var ZipReader = Components.classes["@mozilla.org/libjar/zip-reader;1"].createInstance(Components.interfaces.nsIZipReader);
        var File = Components.classes["@mozilla.org/file/local;1"].createInstance(Components.interfaces.nsILocalFile);

        var DumpText = "";

        File.initWithPath("C:\\write_test1.txt");
        DumpText += "DT (LocalFile): " + File.lastModifiedTime + "<br />";

        File.initWithPath("C:\\zip1.zip");
        ZipReader.open(File);
        DumpText += "DT (ZipItem): " + ZipReader.getEntry("write_test.txt").lastModifiedTime + "<br />";

        ZipReader.close();

        document.write(DumpText);
(Reporter)

Comment 6

7 years ago
For item 3, you can use the part of the script of the last post and add: 

        DumpText += "Compression: " + ZipReader.getEntry("write_test.txt").compression + "<br />";
(Reporter)

Comment 7

7 years ago
For item 5, if you create an empty zip file (I used 7-zip) "C:\zip1.zip", you get an error saying that the zip is corrupted (you get the error if you open an empty zip using either the reader or the writer):

        netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");

        var ZipReader = Components.classes["@mozilla.org/libjar/zip-reader;1"].createInstance(Components.interfaces.nsIZipReader);
        var File = Components.classes["@mozilla.org/file/local;1"].createInstance(Components.interfaces.nsILocalFile);

        var DumpText = "";

        File.initWithPath("C:\\zip1.zip");
        ZipReader.open(File);
        ZipReader.close();
(Reporter)

Comment 8

7 years ago
For item 6, is not so much a bug but a feature that is lacking.

I hope I provided enough information for you guys to duplicate the issues.  Let me know if you need additional help.

Comment 9

7 years ago
I'll look into fixing these,but I wont have time to get to them right away. In the meantime do you want to try it yourself? Much of this should be trivial
(Reporter)

Comment 10

7 years ago
Taras, are you asking me to look at this?  I don't have the ability to turn my machine into a development system for Firefox.

Besides, I am able to work-around all of the issues *EXCEPT* issue 2.  I need to get the correct datetime from the zip entries.  Thanks!

Comment 11

7 years ago
(In reply to comment #10)
> Taras, are you asking me to look at this?  I don't have the ability to turn
> my machine into a development system for Firefox.
> 
> Besides, I am able to work-around all of the issues *EXCEPT* issue 2.  I
> need to get the correct datetime from the zip entries.  Thanks!

ok. I'll look into that one first

Comment 12

7 years ago
So lastModifiedTime doesn't return an invalid date. It returns PRTime which is measured in microseconds, so the proper thing to do is 
new Date(item.lastModifiedTime/1000). Whoever wrote this interface was in a silly mood when they exported a raw prtime.

Comment 13

7 years ago
.manifestEntriesCount returns the number of entries in the manifest, not in the zip files. So 0 is correct.

Please attach a zipfile where nsIZipEntry.compression==8 is incorrect.

CCing Dave for the zipwriter issues.
(Reporter)

Comment 14

7 years ago
Created attachment 538417 [details]
Sample zip file where compression=8
(Reporter)

Comment 15

7 years ago
Taras thanks for looking into these items!

I didn't know what PRTime meant until now.  Thanks again!
(In reply to comment #0)
> 4. nsIZipWriter.addEntryDirectory() doesn't put the specified date time
> modified.

Was this just a misunderstanding about what kind of times it returns? I did some quick tests and this worked fine for me.

> 5. nsIZipWriter.open() and nsIZipWriter.open() are unable to open an empty
> zip file, they return an error saying that the file is corrupted.

I assume you meant nsIZipReader for one of those? For nsIZipWriter at least we trip over this test: http://mxr.mozilla.org/mozilla-central/source/modules/libjar/zipwriter/src/nsZipWriter.cpp#142

It may be as simple as correcting that to be >= but I'd have to re-read the code to check.

> 6. nsIZipWriter and nsIZipWriter don't appear to support password protected
> zip files.

Yeah this isn't something that's ever been considered necessary.
Component: XPCOM → Networking: JAR
(Reporter)

Comment 17

7 years ago
Dave,

Sorry yes.  I did mean to say nsIZipWriter and nsIZipReader.

I am sure that issue 4 had something to do with the fact that I didn't understand the data type that is implemented with the interface (see issue 3).
Whiteboard: [necko-would-take]
You need to log in before you can comment on or make changes to this bug.