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

Flawed ZLib inflateRaw output #7625

Closed
5saviahv opened this issue Nov 20, 2020 · 4 comments
Closed

Flawed ZLib inflateRaw output #7625

5saviahv opened this issue Nov 20, 2020 · 4 comments
Assignees

Comments

@5saviahv
Copy link

5saviahv commented Nov 20, 2020

NWJS Version : 0.49.2 & 0.50.0
Operating System : Linux x64

Expected behavior

inflate should be able extract deflate streams without losses

Actual behavior

I used SHA1 hashes since SHA was created for verify data integrity.

Input data before deflate 1a152d782882a65a39249fd655bfa7ad92746097
output data after deflate d2aaec6e14bf9aca9f805f37eab0e5d1f0042ef4

compressed data

output data hash after inflate c27789e1480426147283ec99d2b3e21f224c77b6

When you look data there seems to be data loss middle of the extracted data filled with 00 bytes

How to reproduce

  • code I used for for testing:
<!DOCTYPE html>
<html>
<head>
  <meta charset="UTF-8">
  <title>Test "zlib.inflateRawSync"</title>
</head>
<body>
    <script>
        document.write('Welcome');

        function readData(file){
            // node crypto
            const ncrypt = require('crypto');
            const fs = require('fs')
            const zlib = require('zlib')

            fs.readFile(file, (err, data) => {
                if (err) throw err;
                // Test Extracted Data
                const shasum1 = ncrypt.createHash('sha1');
                shasum1.update(data);
                console.log(`File content hash: ${shasum1.digest('hex')}`);

                // Extract Data                
                const res = zlib.inflateRawSync(data);

                // Test Extracted Data
                const shasum2 = ncrypt.createHash('sha1');
                shasum2.update(res);
                console.log(`Extracted data hash: ${shasum2.digest('hex')}`);
            });
        }

        readData('./compressed.bin');
    </script>
</body>
</html>
  • when I used, older NWJS v0.48.3 Zlib returns correct value

->

@bluthen
Copy link
Contributor

bluthen commented Nov 21, 2020

Your are confusing zlib(gzip) with zip (pkzip). You hashes only are correct when unzip with pkzip not zlib. zlib mearly compresses or uncompress while zip also is a container.

Perhaps node-zip can do what you'd like:
https://github.com/daraosn/node-zip

It is the difference between:
gzip -d compressed.zip
and
unzip compressed.zip

https://en.wikipedia.org/wiki/ZIP_(file_format)
https://en.wikipedia.org/wiki/Gzip

@bluthen
Copy link
Contributor

bluthen commented Nov 21, 2020

I was saying zlib doen't handle zip archives. I think I was confused because of the uploaded file compress.zip. Sorry to add to the confusion.

I've tried this on node v15.0.1 by itself (not as part of nwjs), and it works correctly, so it seems to specifically be a nwjs issue.

@5saviahv
Copy link
Author

I had errors so I fabricated zip file so I can verify is deflate working. I was able extract data with other zip programs. but NWJS ZLIB was not able extract it it.

I updated my first comment. Sorry for confusion.

@rogerwang rogerwang self-assigned this Nov 22, 2020
@rogerwang
Copy link
Member

Thanks for reporting. Fixed in https://dl.nwjs.io/live-build/nw50/20201124-151641/caac9e090/v0.50.1/

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants