brendan-duncan / archive

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

`ArchiveFile.rawContent` is null when decoded from an Archive #339

Closed jmagman closed 4 months ago

jmagman commented 4 months ago

This test passes on 3.3.2 but fails on >=3.3.3:

final Archive archive = Archive()
  ..addFile(ArchiveFile('AndroidManifest.xml', 100,  List<int>.filled(100, 0)));

final File apk = fileSystem.file('test.apk')
  ..writeAsBytesSync(ZipEncoder().encode(archive)!);

final Archive decodedArchive = ZipDecoder().decodeBytes(apk.readAsBytesSync());
for (final ArchiveFile archiveFile in decodedArchive.files) {
  expect(archiveFile.rawContent, isNotNull);
  expect(archiveFile.rawContent!.length, 6);
}

During decodeBytes zf is a ZipFile. https://github.com/brendan-duncan/archive/blob/98e1158d689e73f26f31f4c2188920c3746aa3b9/lib/src/zip_decoder.dart#L42-L43

Which is a FileContent, and _rawContent is not set. Which means the decoded ArchiveFile.rawContent is unexpectedly null. https://github.com/brendan-duncan/archive/blob/98e1158d689e73f26f31f4c2188920c3746aa3b9/lib/src/archive_file.dart#L84-L86

I would instead expect the ArchiveFile.rawContent at this point to be the same as the ZipFile.rawContent: https://github.com/brendan-duncan/archive/blob/98e1158d689e73f26f31f4c2188920c3746aa3b9/lib/src/zip/zip_file.dart#L183-L188

Looks like it was caused around https://github.com/brendan-duncan/archive/commit/3dd6a0534cbc26c20ab0e6e541c87772836a2c06

jmagman commented 4 months ago

Context is I'm trying to bump the Flutter command line tool from 3.3.2 to >=3.5.0, higher than the security advisory fixes, and past when pointycastle was removed https://github.com/flutter/flutter/issues/149427#issuecomment-2142707624. I'm open to suggestions for workarounds: https://github.com/flutter/flutter/blob/3bc1f517c0365ab1dcdbfb6378dfa7481148b8da/packages/flutter_tools/lib/src/base/analyze_size.dart#L154-L161

brendan-duncan commented 4 months ago

Thanks for the report, I'll get whatever is going wrong fixed.

I am working on a 4.0 branch, I'll make sure whatever gets fixed is applied to that too.

brendan-duncan commented 4 months ago

I pushed a fix to the main branch. I'll work on a release publish shortly.

jmagman commented 4 months ago

Thanks for the quick response!

brendan-duncan commented 4 months ago

Published to 3.6.1. I added a test based on your example, so I'm assuming it's good now.

jmagman commented 4 months ago

Published to 3.6.1. I added a test based on your example, so I'm assuming it's good now.

It worked, thank you! Feel free to close.