brendan-duncan / archive

Dart library to encode and decode various archive and compression formats, such as Zip, Tar, GZip, ZLib, and BZip2.
MIT License
395 stars 130 forks source link

#312 zipDirectory - ZipFileEncoder is initialized with a password #314

Closed hrmoh closed 5 months ago

hrmoh commented 6 months ago

I've encountered another null check operator on a null value with the same scenario, this time the _mac parameter was null, I changed the corresponding line, and tested the zip file and ensured it has no problem. Thanks

tototo23 commented 5 months ago

Hi ! It looks directly related to my issue https://github.com/brendan-duncan/archive/issues/318 😄

I tried to use the master branch today instead of the v3.4.10 from pub.dev I keep the same code :

ZipFileEncoder(password: Config.zipLogsPassword).zipDirectory(tempPath, filename: finalZipFile.path);

Now, it doesn't generate a null error when i generate a password-zip from a folder having subfolder, but :

Do you have an idea if it remains a bug, or if i'm missusing the lib? Or missunderstanding zip usage?

hrmoh commented 5 months ago

Hi ! It looks directly related to my issue #318 😄

I tried to use the master branch today instead of the v3.4.10 from pub.dev I keep the same code :

ZipFileEncoder(password: Config.zipLogsPassword).zipDirectory(tempPath, filename: finalZipFile.path);

Now, it doesn't generate a null error when i generate a password-zip from a folder having subfolder, but :

* I can open the zip file with Windows without asking any password, i can browse the full tree

* I can't uncompress it (using Windows explorer still), or open/copy any file, there is an error

* only the root files appear to have a size, the files in subfolders have a size of 0ko (maybe only cause very small once compressed? or size not visible when encrypted?)

Do you have an idea if it remains a bug, or if i'm missusing the lib? Or missunderstanding zip usage?

I'm not an expert to answer any of these, but being able to view list of files for a password-protected zip file is not a bug in my opinion, RAR format provides an additional option to have an additional protection level and without password you could not see list of files but ZIP does not have this option. And in case of Windows Explorer (Win11) I guess it generally does not support uncompressing password protected zip files.

hipiyayo commented 5 months ago

Same problem here !

tototo23 commented 5 months ago

@hrmoh Thank you for you answer ! I confirm that somezip files can be browse before asking the password, apparently ;)

I've tried with master branch to zip (with password) a folder, having subfolders and some empty files (0 byte). i keep having a null pointer exception.

It looks to come from lib\src\zip_encoder.dart line 369 (main branch, commit from January 24th) :

    if (password != null) {
      output.writeBytes(_mac!);
    }

But here i have _mac == null. I don't know if it is because _mac should never be null with a password, or if the if condition is wrong and should be "if (_mac != null)". Would you have any idea?

brendan-duncan commented 5 months ago

Sorry I've neglected looking into this for so long. I'll try to get to it soon.

tototo23 commented 5 months ago

Sorry I've neglected looking into this for so long. I'll try to get to it soon.

Than you very much :)

brendan-duncan commented 5 months ago

Sorry it took so long to get back to this.

As for the discussion on the ability to browse encrypted zips, the ZIP format does not encrypt the file information, just the file content. Some version of the PKZip format (version 6.2+) can encrypt the central directory, but this library doesn't have that.

tototo23 commented 5 months ago

Hi @brendan-duncan , thank you very much for the information about the difference between content encryption and browsing one. It's intresting to know :) Thanks to both of you with @hrmoh , i've seen your work fixed the error I had (I fixed it locally in my project, but I know that on the next release I can switch back to the pub.dev new version of the package).

brendan-duncan commented 5 months ago

I'll do a version update publish soon, just a couple more things I wanted to get fixed up. Work & life have been busier than usual, that's why I've been so slow to get to this Dart stuff. But I'll try my best to get the release finished soon so this fix is out there. Thank you very much for it.