Adding to .zip archive removes file system access rules
Nobody has claimed this yet.
Assessment
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Newbie friendliness
- 45/100
Research direction
Start in src/ICSharpCode.SharpZipLib/Zip/ZipFile.cs at the finalization code around lines 3132-3143 and the temporary and final output handling around lines 4663-4713. Reproduce the issue with the supplied AddEntryRevertingFilePermissions test, then add regression coverage showing that an access rule on the archive remains after CommitUpdate().
Written by the indexing model from the issue text.
Description
When adding to a .zip archive on disk, the update does not happen in place. Instead, a temporary .zip file with the updated contents is created in a temporary directory first, which replaces the original archive after a successful write. As a result, any file system access rules set on the .zip archive that is updated are lost.
Steps to reproduce
- Run the snippet below in a debugger
[Test]
[Category("Zip")]
[Category("CreatesTempFile")]
public void AddEntryRevertingFilePermissions()
{
const string TestValue = "0001000";
string tempFile = "c:/temp/";
Assert.IsNotNull(tempFile, "No permission to execute this test?");
tempFile = Path.Combine(tempFile, "SharpZipTest.Zip");
// create empty zip file
using (ZipFile f = ZipFile.Create(tempFile))
{
f.BeginUpdate();
f.CommitUpdate();
}
Console.WriteLine("break here and manually amend permissions for c:/temp/SharpZipTest.Zip by adding a rule");
using (ZipFile f = new ZipFile(tempFile))
{
var m = new StringMemoryDataSource(TestValue);
f.BeginUpdate();
f.Add(m, "a.dat");
f.CommitUpdate();
}
Console.WriteLine("permissions for c:/temp/SharpZipTest.Zip are reverted");
}
- Break in the middle and amend permissions to the file by adding an access rule.
- Run to completion and verify that the file permission has reverted.
Expected behavior
File permissions should be retained
Actual behavior
File permissions inherited from temporary directory (e.g. C:\Users\username\AppData\Local\Temp\) are set
Version of SharpZipLib
Obtained from (only keep the relevant lines)
- Compiled from source, commit: https://github.com/icsharpcode/SharpZipLib/commit/cd5310f5b7eed595110b76a2f7ae5ee013cc50f1
Further detail
The update is finalised: (directUpdate is false)
https://github.com/icsharpcode/SharpZipLib/blob/cd5310f5b7eed595110b76a2f7ae5ee013cc50f1/src/ICSharpCode.SharpZipLib/Zip/ZipFile.cs#L3132-L3143
The temporary output (pointing to a temporary directory ) is created at https://github.com/icsharpcode/SharpZipLib/blob/cd5310f5b7eed595110b76a2f7ae5ee013cc50f1/src/ICSharpCode.SharpZipLib/Zip/ZipFile.cs#L4663-L4669
The final output is created at
https://github.com/icsharpcode/SharpZipLib/blob/cd5310f5b7eed595110b76a2f7ae5ee013cc50f1/src/ICSharpCode.SharpZipLib/Zip/ZipFile.cs#L4676-L4713
- Dominant language
- C#
- Stars
- 3.9k
- Forks
- 1k
- PR merge metrics
- No merged PRs in 30d
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from icsharpcode/SharpZipLib
-
*no response* bug
Difficulty 1/5 Under an hour Newbie friendliness 78/100
icsharpcode/SharpZipLib#905 · 1 comment ·
-
bug bzip2
Difficulty 4/5 3-5 days Newbie friendliness 45/100
icsharpcode/SharpZipLib#904 ·
-
SetLevel in ZipFile Openenhancement zip
Difficulty 2/5 1-2 days Newbie friendliness 55/100
icsharpcode/SharpZipLib#903 ·
-
*no response* bug
Difficulty 4/5 3-5 days Newbie friendliness 32/100
icsharpcode/SharpZipLib#901 · 1 comment ·
-
*no response* bug
Difficulty 4/5 3-5 days Newbie friendliness 35/100
icsharpcode/SharpZipLib#894 · 1 comment ·