Hacktoberfest 2026: le issue che i maintainer hanno segnato per ottobre, aperte e adatte ai principianti. Sfoglia le issue Hacktoberfest

Adding to .zip archive removes file system access rules

Aperta
#654 12 commenti 0 reazioni 0 assegnatari Vedi su GitHub

Nessuno ha ancora preso questa issue.

Valutazione

Difficoltà
3/5
Tempo stimato
1-2 giorni
Idoneità per principianti
45/100
Tipo di issue
Bug
Chiarezza
Specificata chiaramente
Stato di attività
Ferma
Stack tecnologico
csharp
Ambito
backend

Direzione di ricerca

Iniziare in src/ICSharpCode.SharpZipLib/Zip/ZipFile.cs, nel codice di finalizzazione intorno alle righe 3132-3143 e nella gestione dell’output temporaneo e finale intorno alle righe 4663-4713. Riprodurre il problema con il test fornito AddEntryRevertingFilePermissions, quindi aggiungere una copertura di regressione che dimostri che una regola di accesso sull’archivio rimane dopo CommitUpdate().

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

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
  1. 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");
		}
  1. Break in the middle and amend permissions to the file by adding an access rule.
  2. 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)
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

Lingua principale
C#
Stelle
3.9k
Fork
1k
Metriche di merge delle PR
Nessuna PR unita negli ultimi 30g

Preparare l'ambiente

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di icsharpcode/SharpZipLib

Tutte le issue di icsharpcode/SharpZipLib

Issue simili

Altre issue su C#

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.