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

CRC fails for streaming ZIP file if compression level set to 0 #98

Closed
harveylee opened this issue Nov 1, 2021 · 6 comments
Closed

CRC fails for streaming ZIP file if compression level set to 0 #98

harveylee opened this issue Nov 1, 2021 · 6 comments

Comments

@harveylee
Copy link

How to reproduce
Zip the attached truck.jpg using the streaming ZIP interface with level set to 0. Try to extract it again using an off-the-shelf ZIP program.

// Node 14.15.4
import fs from 'fs'
import { Zip, AsyncZipDeflate } from 'fflate'

const buf = fs.readFileSync('truck.jpg')
const writeStream = fs.createWriteStream('truck.zip')
const zip = new Zip((err, data, final) => {
  if (err !== null) throw err
  writeStream.write(data)
  if (final) writeStream.end()
})

const file = new AsyncZipDeflate('truck.jpg', { level: 0 })
zip.add(file)
file.push(buf, true)
zip.end()

The problem
Both Windows Explorer and 7-ZIP reports a CRC error when trying to extract truck.jpg from the ZIP file. This doesn't seem to occur using the zip() interface nor at compression levels other than 0 (tried 1, 2, 6, 9). Also other files seem to work, there's something specific about this file and others.

truck

@101arrowz
Copy link
Owner

Thanks for the bug report, I'll look into this in a few days.

@101arrowz
Copy link
Owner

Haven't gotten a chance to check this out yet, but I should have time this weekend, sorry for the delay.

@harveylee
Copy link
Author

If it helps, I switched to using zip() for now, which doesn't seem to suffer from this problem?

i.e. this

import { zip } from 'fflate'
zip({ ... }, (err, data) => { ... })

I also recall running into some (related?) issues at other compression levels with other files, but I forgot to keep notes.

@101arrowz
Copy link
Owner

101arrowz commented Nov 16, 2021

You mentioned it in your original issue, but it's kind of weird because zip and Zip call the same CRC function internally. I definitely need to investigate more.

@101arrowz
Copy link
Owner

I've finally been able to reproduce this error and will fix it as soon as possible.

@101arrowz
Copy link
Owner

Well this was an incredibly stupid error - this package has been unable to do level-0 compression of files above 64kB since its release, it's just never been noticed because level-0 compression for ZIP files doesn't actually use DEFLATE level-0, and most files I tested were under 64kB. Thank you for this bug report, should be fixed in v0.7.2.

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

2 participants