Skip to content
This repository has been archived by the owner on May 15, 2024. It is now read-only.

ZipEntry.Extract: Setting invalid FileAttributes causes exception on unix-based systems #286

Open
ir-dev opened this issue Jan 17, 2024 · 0 comments

Comments

@ir-dev
Copy link

ir-dev commented Jan 17, 2024

Version: DotNetZip 1.16.0

I noticed that when extracting certain zip files (as I later saw zip files with entries with potentially invalid "external file attributes") I was getting an exception:

System.ArgumentException: Invalid File or Directory attributes value. (Parameter 'Attributes')
   at System.IO.FileStatus.SetAttributes(string path, FileAttributes attributes)
   at System.IO.FileSystem.SetAttributes(string fullPath, FileAttributes attributes)
   at Ionic.Zip.ZipEntry.MoveFileInPlace(bool fileExistsBeforeExtraction, string targetFileName, string tmpPath, bool checkLaterForResetDirTimes)
  ..

The issue roots in the following call which will happen at the end of zip extraction process:

File.SetAttributes(targetFileName, (FileAttributes) _ExternalFileAttrs);

I looked into it and saw that i tried to extract ZipEntry with Attribute property value: 0x81000000 which obviously wouldn't work here as the System.IO.FileAttributes doesn't even have such a bit flag defined.

For me, the strange thing about it is that the same extraction with the same data previously ran on a Win system without any problems, whereas now I use Linux on amd64 arch. Hence, I think the BCL for System.IO.FileStatus behaves differently in the corresponding runtime version between these operating systems, in the sense that the flag enum is validated on Unix-based systems, while invalid values being probably ignored on Win.

However, I think it doesn't matter if the FileAttributes are invalid or even if the BCL there has an inconsistency, in my opinion it should actually never throw in this place while setting file attributes. If they were invalid, I would assume that the library is simply using default values for the attributes or even not setting them at all. Eventually, I think this approach will be better, especially considering that other zip libraries ignore setting the file attributes anyway.

Add.: Temporary workaround or even to-go solution for this issue will be to only set ZipEntry Attributes property to valid FileAttributes with valid bit flags specified in the enum otherwise setting the prop to FileAttributes.None.

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

No branches or pull requests

1 participant