brendan-duncan / archive

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

Zip extraction causing index out of range. [Unzipping with password issue] #264

Open fz3hra opened 1 year ago

fz3hra commented 1 year ago

Hello everyone, I am actually receiving some data which is in base64 format from the backend.

However when zipping then unzipping the file which consists of decoded base64, I am unable to bypass the decodeBytes as it throws me an error of index out of range.

When downloaded to windows, it can be opened without any issue by using the password.

This is where the error occurs: archive = ZipDecoder().decodeBytes(bytes, verify: true, password: zipPassword);

I am using archive version: 3.3.7with flutter sdk version 3.3.0

Can anyone please help me find a way around this?

Thank you so much cc. @brendan-duncan

error with stack:

I/flutter (30210): Error occurred while extracting the zip file: Invalid argument(s): 4294967366 I/flutter (30210): Stack trace: #0 List.[] (dart:core-patch/growable_array.dart:264:36) I/flutter (30210): #1 InputStream.readUint32 input_stream.dart:249 I/flutter (30210): #2 new ZipFile zip_file.dart:99 I/flutter (30210): #3 new ZipFileHeader zip_file_header.dart:101 I/flutter (30210): #4 new ZipDirectory.read zip_directory.dart:53 I/flutter (30210): #5 ZipDecoder.decodeBuffer zip_decoder.dart:24 I/flutter (30210): #6 ZipDecoder.decodeBytes zip_decoder.dart:16 I/flutter (30210): #7 TestFileExtraction.extractFilesToDirectory

mudlee commented 1 year ago

I experience the same problem as of today with the same versions.

My code:

final archive = ZipDecoder().decodeBuffer(InputFileStream(zip.path!), password: password);

Error:

[ERROR:flutter/runtime/dart_vm_initializer.cc(41)] Unhandled Exception: RangeError: Value not in range: -15326
#0      _rangeCheck (dart:typed_data-patch/typed_data_patch.dart:5231:5)
#1      _ByteBuffer.asUint8List (dart:typed_data-patch/typed_data_patch.dart:1936:5)
#2      new Uint8List.view (dart:typed_data:883:19)
#3      OutputStream.subset (package:archive/src/util/output_stream.dart:170:22)
#4      Inflate._decodeHuffman (package:archive/src/zlib/inflate.dart:319:34)
#5      Inflate._parseFixedHuffmanBlock (package:archive/src/zlib/inflate.dart:214:12)
#6      Inflate._parseBlock (package:archive/src/zlib/inflate.dart:119:13)
#7      Inflate._inflate (package:archive/src/zlib/inflate.dart:91:12)
fz3hra commented 1 year ago

@mudlee were u able to find a work about please?

sophisticode commented 1 year ago

I have the same issue.

It works fine with archive 3.3.2 It fails with archive 3.3.3

So you may use version archive 3.3.2 if you need to unzip encrypted files.