Skip to content

Unpredictable checksum #3613

Open
Open

Description

@kylekatarnls

Hello,

Here is the command I run:

npm exec web-ext -- build --overwrite-dest --source-dir=distribution -a . -n package.zip
md5sum package.zip

Everytime I run this command (without changing anything in distribution), the checksum (a priori containing some file modification timestamps) will be different.

However paradoxically, extension stores, like the Firefox store, will ask developers to provide steps to build the extension package and require it to produce the exact same checksum as the ZIP that you submitted.

How can I build a ZIP for my extension that would always produce the exact same ZIP?

Activity

  1. Rob--W commented on Feb 12, 2026

    @Rob--W
    Member

    I tried it myself with an extension containing many files, at https://addons.mozilla.org/firefox/downloads/file/4207386/crxviewer-1.7.0.xpi

    When I use xxd I see that the sizes are identical but the contents are different, possibly a different ordering.
    When I use zipinfo on the generated zip files, I can see inconsistent orderings, confirming my suspicion.

    We should use a consistent ordering.

  2. Rob--W commented on Feb 12, 2026

    @Rob--W
    Member

    We call zipDir at

    web-ext/src/cmd/build.js

    Lines 134 to 136 in 2adf895

    const buffer = await zipDir(sourceDir, {
    filter: (...args) => fileFilter.wantFile(...args),
    });

    zipDir is the zip-dir library, which is essentially a single file implementation at https://github.com/jsantell/node-zip-dir/blob/master/index.js

    The package itself is relatively light, the actual zip generation is done by jszip (https://www.npmjs.com/package/jszip).
    That library has not been updated for 6 years. We should cut out this middle man, and implement a deterministic file reading logic ourselves, and directly use jszip.

    @kylekatarnls Do you want to submit a patch to implement this?

  3. kylekatarnls commented on Feb 16, 2026

    @kylekatarnls
    Author

    I took a look but apparently it's not just about file order, all of the points below must match:

    • date of files
    • date of folders (automatically created from file paths but with current timestamp by default)
    • order of the structure (due to the way zipBuffer is made, i.e. using recursion, it has to be changed so it first do the listing recursively without starting to queue with zip.file(), then apply all the zip.file() in a second step after listing)
  4. Rob--W commented on Feb 16, 2026

    @Rob--W
    Member

    I took a look but apparently it's not just about file order, all of the points below must match:

    • date of files
    • date of folders (automatically created from file paths but with current timestamp by default)

    If timestamps of the files don't change, running the same command twice will generate the same output.

    • order of the structure (due to the way zipBuffer is made, i.e. using recursion, it has to be changed so it first do the listing recursively without starting to queue with zip.file(), then apply all the zip.file() in a second step after listing)

    Yep, that is the issue here. I provided pointers to the relevant implementation details at #3613 (comment). Are you interested in contributing a patch? If not, I will make this issue available to other interested contributors.

  5. kylekatarnls commented on Feb 16, 2026

    @kylekatarnls
    Author

    If timestamps of the files don't change, running the same command twice will generate the same output.

    File timestamps use the one from the actual file, but folder timestamps use current timestamp. So even if you have only 1 file in a folder, such as folder/index.html, then on first run you get:

      Length      Date    Time    Name
    ---------  ---------- -----   ----
            0  2026-02-16 19:19   folder/
          295  2026-02-10 12:10   folder/index.html
    

    And running it again later the folder date-time will change even if was not touched:

      Length      Date    Time    Name
    ---------  ---------- -----   ----
            0  2026-02-16 19:20   folder/
          295  2026-02-10 12:10   folder/index.html
    

    I was considering the option createFolder: false but it might have an impact for those having empty folders in their package, I don't know if it's a thing that really needs to be supported though.

    I'm taking a look and trying to make in in 2 steps, but it won't just touch the part of the code you mentioned, it will probably end up with a rather significant rewriting of zip-dir.js I don't promise to finish that soon.

  6. Rob--W commented on Feb 16, 2026

    @Rob--W
    Member

    The .file method can also be used to create a directory: https://stuk.github.io/jszip/documentation/api_jszip/file_data.html#arguments

    So you can use that to "create" the directory before adding the file, and use createFolders: false on the files for clarity.

  7. kylekatarnls commented on Feb 20, 2026

    @kylekatarnls
    Author

    Hello, I have another question/concern:

    Listing files, then sorting before zipping them should be fine.

    But now there is also the zipping phase that happen in parallel and you can start zipping A before B and get B zipped bytes ready before A ones.

    So this means we have to save the result for B in a variable and wait for A content to be ready and appended to the result file, before we actually write the content for B.

    As a result writing a deterministic ZIP will consume a bit more memory and take a bit more time than the current version.

    Should it be then an option, so users can decide?

    E.g.
    zipMode: 'fast' | 'deterministic'

  8. Rob--W commented on Feb 20, 2026

    @Rob--W
    Member

    The current implementation in web-ext already keeps the generated zip in memory before writing to disk, opposed to streaming the zip.

    I don't think that memory efficiency is a problem yet; keep in mind that the resulting file should be sufficiently reasonably sized to be loaded by users in a web browser.

    The original zip-dir library did not limit the size of the files either, only the number of concurrently open files.

  9. Gueupo commented on May 5, 2026

    @Gueupo

    Thanks @kylekatarnls and @Rob--W for the original investigation. Trying to have a stab at it. Opening a PR #3709 using JSZip directly with sorted entries, a fixed default timestamp (1980-01-01) with an override parameter.

  10. 3692189725im-bit commented on Oct 24, 2026

    @3692189725im-bit
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Fields

    Priority

    None yet

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions