weltkante/managed-lzma

sandbox-7z example code fails when archive contains empty file

ninad2110 opened this issue ยท 7 comments

If 7z archive already contains folder/directory it fails while reading metadata

  • throws InvalidDataException exception in ArchiveMetadataReader.

Class: ArchiveMetadataReader
Method: ReadSectionDetails()
System.IO.InvalidDataException: 'Found invalid data while decoding.'

I created folder & archive using managed-lzma/sandbox-7z/Program.cs
Just added *ABCfolder* (before line 116) while creating archive, 7z file created successfully
I checked 7z by unpacking using other tools.

I'll have a look, but it'd help if you can be more detailed on what you changed to produce this file (alternatively fork the repo and point me to your changes)

Thank you weltkante!

Fork repo: ninad2110 / managed-lzma
Summary of changes

  1. Added sample folder in /sandbox-7z/
    Example/
    Sample/ => Contains files to be archived
    Pack/ => Sample folder will be archived to trial.7z pack = true => Success
    Unpack/ => Unpack trial.7z here pack=false, unpacking fails
  2. sandbox-7z is set as startup project
  3. Modified \sandbox-7z\Program.cs
    pack = true calls CreateArchieve() ==> success
    pack = false calls UnpackArchive() ==> fails with InvalidDataException exception

Note: Changed Compression\Lzma\EncoderSettings.cs to set level=1 (LZMA:16), but not related to above changes

Doesn't look like it has anything to do with relative paths, but rather with empty files. Not sure what goes wrong there, either I'm encoding them wrong or the metadata reader is overly strict. I'll check in the next few days why the zero size check is in there.

  • Checked by adding contents to empty file(s), and it worked.

  • I have another 7z which isn't working, actually I tried to create similar 7z. To me, looks like some other issue with archived 7z file. I will do more tests and analyze and get back on this.

To me, looks like some other issue with archived 7z file.

The stack trace of the exception may be useful to classify it if you can't share the archive or repro it (though I can't guarantee I can fix it based on an exception stacktrace alone)

System.IO.InvalidDataException
HResult=0x80131501
Message=Found invalid data while decoding.
Source=managed-lzma
StackTrace:
at ManagedLzma.SevenZip.FileModel.ArchiveFileModelMetadataReader.ReadMetadata(Stream stream, PasswordStorage password) in D:\github\ninad2110\managed-lzma\shared\SevenZip\ArchiveFileModel.cs:line 303
at sandbox_7z.Program.UnpackArchive(String archiveFileName, String targetDirectory, PasswordStorage password) in D:\github\ninad2110\managed-lzma\sandbox-7z\Program.cs:line 146
at sandbox_7z.Program.UnpackArchive(String archiveFileName, String targetDirectory, String password) in D:\github\ninad2110\managed-lzma\sandbox-7z\Program.cs:line 132
at sandbox_7z.Program.Main() in D:\github\ninad2110\managed-lzma\sandbox-7z\Program.cs:line 43
debug

Added archive in
Fork repo: ninad2110 / managed-lzma
Archive file : /sandbox-7z/Example/Pack/Data.7z

The second exception is due to containing attribute metadata for a directory in a way which would not have been generated by the codebase I ported. In other words its a genuine "this data is not supposed to be here" exception. I'd have to investigate how newer versions of the 7zip codebase would treat it, but thats not going to happen anytime soon.