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

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

Open
ninad2110 opened this issue Apr 16, 2021 · 7 comments
Open

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

ninad2110 opened this issue Apr 16, 2021 · 7 comments
Assignees
Labels

Comments

@ninad2110
Copy link

ninad2110 commented Apr 16, 2021

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.

@ninad2110 ninad2110 changed the title Unpack achieve fails if 7z contains folder/directory Unpack 7z archive fails if it contains folder/directory Apr 16, 2021
@weltkante
Copy link
Owner

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)

@ninad2110
Copy link
Author

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

@weltkante
Copy link
Owner

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.

@weltkante weltkante changed the title Unpack 7z archive fails if it contains folder/directory sandbox-7z example code fails when archive contains empty file Apr 19, 2021
@weltkante weltkante added the bug label Apr 19, 2021
@weltkante weltkante self-assigned this Apr 19, 2021
@ninad2110
Copy link
Author

  • 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.

@weltkante
Copy link
Owner

weltkante commented Apr 20, 2021

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)

@ninad2110
Copy link
Author

ninad2110 commented Apr 20, 2021

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

@weltkante
Copy link
Owner

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.

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

No branches or pull requests

2 participants