Closed Bug 662687 Opened 13 years ago Closed 5 years ago

Bugs in nsIZipReader, nsIZipWriter, nsIZipEntry

Categories

(Core :: Networking: JAR, defect, P5)

2.0 Branch
x86
Windows XP
defect

Tracking

()

RESOLVED INVALID

People

(Reporter: vb4guy, Unassigned)

Details

(Whiteboard: [necko-would-take])

Attachments

(1 file)

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
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
Component: Networking: JAR → XPCOM
OS: Windows 7 → Windows XP
Version: unspecified → 2.0 Branch
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.
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);
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);
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);
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 />";
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();
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.
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
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!
(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
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.
.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.
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
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]
Bulk change to priority: https://bugzilla.mozilla.org/show_bug.cgi?id=1399258
Priority: -- → P5

I'm closing this issue as it seems that many of the issues were just misunderstandings of the API. If there are remaining issues please file a single bug per issue.

Status: UNCONFIRMED → RESOLVED
Closed: 5 years ago
Resolution: --- → INVALID

Hello! Thank you very much for your reply. Now I have a requirement add password while calling nsizipWriter to compress into ZIP file. But I don't see the place where the password is set in the document of nsizipWriter. I don't know how to implement it now. I hope to get your help or guidance. Thank you very much. My English is not very good, you hope to understand! Thank you very much!!

(In reply to gf_w from comment #21)

Hello! Thank you very much for your reply. Now I have a requirement add password while calling nsizipWriter to compress into ZIP file. But I don't see the place where the password is set in the document of nsizipWriter. I don't know how to implement it now. I hope to get your help or guidance. Thank you very much. My English is not very good, you hope to understand! Thank you very much!!

Support for passwords in zip files is not currently implemented nor do I think it likely that we would accept a patch for it at this time.

You need to log in before you can comment on or make changes to this bug.

Attachment

General

Creator:
Created:
Updated:
Size: