diff --git a/src/Zip Tests/Streams.cs b/src/Zip Tests/Streams.cs index a4993ae..ba67847 100644 --- a/src/Zip Tests/Streams.cs +++ b/src/Zip Tests/Streams.cs @@ -210,6 +210,29 @@ public void ReadZip_OpenReader() } + // Read a file consisting of a 16 byte header and one embedded zip archive + [TestMethod] + public void ReadZip_WithOffset() + { + string filename = Path.Combine(CurrentDir, "zips\\offset.bin"); + string header = null; + int entries = 0; + + using (FileStream fs = new FileStream(filename, FileMode.Open, FileAccess.Read, FileShare.Read)) + using (BinaryReader br = new BinaryReader(fs)) + { + header = Encoding.ASCII.GetString(br.ReadBytes(16)); + using (ZipFile zip = ZipFile.Read(fs)) + { + entries = zip.Entries.Count; + } + } + + Assert.AreEqual("16-byte header\0\0", header, "Error reading header"); + Assert.AreEqual(1, entries, "Error reading embedded zip file"); + } + + [TestMethod] public void ZOS_Create_WithComment_wi10339() { diff --git a/src/Zip Tests/Zip Tests.csproj b/src/Zip Tests/Zip Tests.csproj index 8c7be4b..5386b2c 100644 --- a/src/Zip Tests/Zip Tests.csproj +++ b/src/Zip Tests/Zip Tests.csproj @@ -165,6 +165,9 @@ Always + + Always + diff --git a/src/Zip Tests/zips/offset.bin b/src/Zip Tests/zips/offset.bin new file mode 100644 index 0000000..d9fa011 Binary files /dev/null and b/src/Zip Tests/zips/offset.bin differ diff --git a/src/Zip.Shared/OffsetStream.cs b/src/Zip.Shared/OffsetStream.cs index 525019a..a846274 100644 --- a/src/Zip.Shared/OffsetStream.cs +++ b/src/Zip.Shared/OffsetStream.cs @@ -90,7 +90,18 @@ public override long Position public override long Seek(long offset, System.IO.SeekOrigin origin) { - return _innerStream.Seek(_originalPosition + offset, origin) - _originalPosition; + switch (origin) + { + case SeekOrigin.Begin: + return _innerStream.Seek(_originalPosition + offset, origin) - _originalPosition; + + case SeekOrigin.Current: + case SeekOrigin.End: + return _innerStream.Seek(offset, origin) - _originalPosition; + + default: + throw new ArgumentOutOfRangeException(nameof(origin), origin, "Invalid seek origin"); + } }