Skip to content

Commit

Permalink
Merge pull request #541 from avao/master
Browse files Browse the repository at this point in the history
UT and Fix for: Index out of range exception from gzip #532
  • Loading branch information
adamhathcock committed Oct 19, 2020
2 parents f36167d + 0268713 commit aa6575c
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 10 deletions.
11 changes: 1 addition & 10 deletions src/SharpCompress/Compressors/Deflate/GZipStream.cs
Expand Up @@ -384,16 +384,7 @@ public override void Write(byte[] buffer, int offset, int count)
if (_fileName.Contains("\\"))
{
// trim any leading path
int length = _fileName.Length;
int num = length;
while (--num >= 0)
{
char c = _fileName[num];
if (c == '\\')
{
_fileName = _fileName.Substring(num + 1, length - num - 1);
}
}
_fileName = Path.GetFileName(_fileName);
}
}
}
Expand Down
13 changes: 13 additions & 0 deletions tests/SharpCompress.Test/GZip/GZipWriterTests.cs
Expand Up @@ -49,5 +49,18 @@ public void GZip_Writer_Generic_Bad_Compression()
}
});
}

[Fact]
public void GZip_Writer_Entry_Path_With_Dir()
{
using (Stream stream = File.Open(Path.Combine(SCRATCH_FILES_PATH, "Tar.tar.gz"), FileMode.OpenOrCreate, FileAccess.Write))
using (var writer = new GZipWriter(stream))
{
var path = Path.Combine(TEST_ARCHIVES_PATH, "Tar.tar");
writer.Write(path, path); //covers issue #532
}
CompareArchivesByPath(Path.Combine(SCRATCH_FILES_PATH, "Tar.tar.gz"),
Path.Combine(TEST_ARCHIVES_PATH, "Tar.tar.gz"));
}
}
}

0 comments on commit aa6575c

Please sign in to comment.