Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Producing broken (bad CRC) zip archives on Node v15.6.0 #491

Closed
pgrzesik opened this issue Jan 17, 2021 · 4 comments
Closed

Producing broken (bad CRC) zip archives on Node v15.6.0 #491

pgrzesik opened this issue Jan 17, 2021 · 4 comments

Comments

@pgrzesik
Copy link

pgrzesik commented Jan 17, 2021

Hello team 👋

During the investigation of an issue reported in Serverless Framework (serverless/serverless#8772), I've noticed that for the latest release of Node, v15.6.0, archiver will produce broken zip archives with bad CRCs. I've also tested for node10, node12, node14 as well as v15.5.0 and there is no issue, so it seems like it was caused by the latest node release.

Archiver version used: 5.2.0

Below you can find steps to reproduce it using dumbed down version of example from documentation

Snippet
const fs = require('fs');
const archiver = require('archiver');

const output = fs.createWriteStream(__dirname + '/example.zip');
const archive = archiver('zip');

output.on('close', function() {
  console.log(archive.pointer() + ' total bytes');
  console.log('archiver has been finalized and the output file descriptor has closed.');
});

output.on('end', function() {
  console.log('Data has been drained');
});

archive.on('warning', function(err) {
  if (err.code === 'ENOENT') {
    // log warning
  } else {
    // throw error
    throw err;
  }
});

archive.on('error', function(err) {
  throw err;
});

archive.pipe(output);

// append a file from string
archive.append('string cheese!', { name: 'file.txt' });

archive.finalize();

Executing it on v15.6.0 results in archive that when unzipping results in:

> unzip example.zip
Archive:  example.zip
  inflating: file.txt                 bad CRC d1cd8993  (should be 00000000)

While on anything below v15.6.0 it's working without issues:

> unzip example.zip
Archive:  example.zip
  inflating: file.txt

I'd be happy to provide more details if needed, please let me know if there's any way I can help resolving this issue, thanks in advance 🙇

@Aaron1011
Copy link

This is reproduceable with just node-zip-stream:

const Packer = require('./index.js');
const fs = require('fs');
const archive = new Packer(); // OR new Packer(options)

archive.on('error', function(err) {
  throw err;
});

const output = fs.createWriteStream(__dirname + '/new.zip');
archive.pipe(output);

archive.entry('string contents', { name: 'string.txt' }, function(err, entry) {
  if (err) throw err;
  archive.entry(null, { name: 'directory/' }, function(err, entry) {
    if (err) throw err;
    archive.finish();
  });
});

@xfournet
Copy link

Probable root cause : archiverjs/node-crc32-stream#31

@Aaron1011
Copy link

The root cause is nodejs/node#37027

@ctalkington
Copy link
Member

thanks everyone. a new release of crc32-stream has been made.

jthomas added a commit to nimbella/nimbella-deployer that referenced this issue May 13, 2021
archiverjs/node-archiver#491

Due to this issue - the deployer library fails to produce a correct
zip file for remote builds. This causes the remote build to fail.

Also update the runtimes.json to match the current version.
andyli added a commit to hkssprangers/hkssprangers that referenced this issue Feb 11, 2022
jethron added a commit to jethron/hoverboard that referenced this issue Oct 21, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants