-
Notifications
You must be signed in to change notification settings - Fork 88
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
Unexpected EOF when inflating ZIP #208
Comments
I'll look into this and let you know what the issue is soon. The streaming unzip API has needed a bit of work for a while now... |
Still unsure of the issue here @101arrowz? |
Sorry, I've been busy for the last few weeks - I probably won't be able to get to this for a while. To be honest I would just advise against using the streaming unzip API until I can get around to fixing it. |
Hi @101arrowz, I'm encountering the same problem with this file: https://github.com/johan-tribus/fflate/blob/master/file.zip |
Hi 101arrowz Thank you for this great tool. I have the same problem, using unzipSync. I hope you find and solve the problem easily. |
Hi @101arrowz Thank you for this great tool. I had the same problem when using I hope you find and solve the problem easily. |
@johan-tribus I've looked at the file you've attached. The problem is simple and should be easy to fix. First a bit of context: essentially a zip file consists of several building blocks, it usually looks like this:
When reading a .zip archive using the In the file you attached, fflate when iterating over such a The problem is here: Lines 3610 to 3613 in f787356
fflate should verify that it actually encountered if (sig == 0x8074B50) {
const z64 = oc == -2; // is this file in Zip64 format, `oc == -2` seems to mean this, I am not sure
const _sc = z64 ? b8(buf, i + 8) : b4(buf, i + 8); // read 'compressed size' from data descriptor block
if (_sc == i) { // assuming that `i` is how many bytes of [file data x] block were read
is = i += 12 + (oc == -2 && 8), f = 3, this.c = 0;
break;
} else {
// just a coincidence, ignore it
}
} else if (sig == 0x2014B50) { Alternatively, crc-32 can be verified, but byte count is simpler. |
Hi all, Thank you @kajkal for your extensive explanation and suggested changes. I tested it and seems to work as expected. |
@johan-tribus of my two assumptions in the fix suggestion only one is true, i.e. const filepath = './file.zip';
const unzipper = new fflate.Unzip();
unzipper.register(fflate.UnzipInflate);
unzipper.onfile = (file) => {
console.log('file found', { name: file.name, compression: file.compression });
let i = 0;
file.ondata = (err, data, final) => {
if (err) throw err;
console.log(` got decompressed chunk ${i++}`, { bytes: data.length, final });
};
file.start();
};
// my suggestion works when the file is loaded in one piece
unzipper.push(fs.readFileSync(filepath), true);
// but fails when the file is loaded in chunks
const rs = fs.createReadStream(filepath, { highWaterMark: 64 * 1024 /*bytes*/ });
rs.on('data', (chunk) => unzipper.push(chunk));
rs.on('end', () => unzipper.push(new Uint8Array(), true));
// therefore, it cannot be assumed that `i` always means how many bytes of [file data x] block were read From what I understand it would be possible to keep the 'historical' (multiple chunks friendly) compressed size value in the |
The problem
I have a zip file that I can decompress with other decompressors (ubuntu's
unzip
, yazul, python3) but when using fflate the zip is unable to be decompressed.How to reproduce
Using a simple script
with my sample zip file: https://public.chard.com/fflate/address.zip
The text was updated successfully, but these errors were encountered: