mirror of
https://github.com/adamhathcock/sharpcompress.git
synced 2026-09-22 23:15:20 +00:00
Mitigation of problems
This commit is contained in:
@@ -43,12 +43,20 @@ namespace SharpCompress.Common.Zip
|
||||
{
|
||||
_decompressionStream ??= GetCompressedStream();
|
||||
|
||||
_decompressionStream.Skip();
|
||||
|
||||
if (_decompressionStream is DeflateStream deflateStream)
|
||||
if( Header.CompressionMethod != ZipCompressionMethod.None )
|
||||
{
|
||||
rewindableStream.Rewind(deflateStream.InputBuffer);
|
||||
_decompressionStream.Skip();
|
||||
|
||||
if (_decompressionStream is DeflateStream deflateStream)
|
||||
{
|
||||
rewindableStream.Rewind(deflateStream.InputBuffer);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
// We would need to search for the magic word
|
||||
}
|
||||
|
||||
Skipped = true;
|
||||
}
|
||||
var reader = new BinaryReader(rewindableStream);
|
||||
|
||||
@@ -132,7 +132,6 @@ namespace SharpCompress.Readers
|
||||
private void Skip()
|
||||
{
|
||||
var part = Entry.Parts.First();
|
||||
part.Skipped = true;
|
||||
|
||||
if (ArchiveType != ArchiveType.Rar
|
||||
&& !Entry.IsSolid
|
||||
@@ -145,6 +144,7 @@ namespace SharpCompress.Readers
|
||||
{
|
||||
var bytesToAdvance = Entry.CompressedSize;
|
||||
rawStream.Skip(bytesToAdvance);
|
||||
part.Skipped = true;
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -738,13 +738,22 @@ namespace SharpCompress.Test.Zip
|
||||
[Fact]
|
||||
public void Zip_Uncompressed_Skip_All()
|
||||
{
|
||||
string zipPath = Path.Combine(TEST_ARCHIVES_PATH, "Zip.uncompressed.zip");
|
||||
var keys = new string[] { "Folder/File1.txt", "Folder/File2.rtf", "Folder2/File1.txt", "Folder2/File2.txt", "DEADBEEF" };
|
||||
var zipPath = Path.Combine(TEST_ARCHIVES_PATH, "Zip.uncompressed.zip");
|
||||
using (var stream = File.Open(zipPath, FileMode.Open, FileAccess.Read))
|
||||
{
|
||||
IArchive archive = ArchiveFactory.Open(stream);
|
||||
IReader reader = archive.ExtractAllEntries();
|
||||
int x = 0;
|
||||
while (reader.MoveToNextEntry())
|
||||
;
|
||||
{
|
||||
Assert.Equal(keys[x], reader.Entry.Key);
|
||||
x++;
|
||||
}
|
||||
|
||||
// if we implement searching for DataDescriptor on none compressed streams
|
||||
// this would work, see StreamingZipFilePart function FixStreamedFileLocation
|
||||
// Assert.Equal(4, x);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
using System;
|
||||
using System;
|
||||
using System.IO;
|
||||
using SharpCompress.Common;
|
||||
using SharpCompress.IO;
|
||||
@@ -368,5 +368,21 @@ namespace SharpCompress.Test.Zip
|
||||
}
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Zip_ReaderMoveToNextEntry()
|
||||
{
|
||||
var keys = new string[] { "version", "sizehint", "data/0/metadata", "data/0/records" };
|
||||
|
||||
using (var fileStream = File.OpenRead(Path.Combine(TEST_ARCHIVES_PATH, "test_477.zip")))
|
||||
using (var reader = ZipReader.Open(fileStream))
|
||||
{
|
||||
foreach( var key in keys)
|
||||
{
|
||||
reader.MoveToNextEntry();
|
||||
|
||||
Assert.Equal(reader.Entry.Key, key);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user