Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

UT and Fix for: Index out of range exception from gzip #532 #541

Merged
merged 1 commit into from Oct 19, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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);
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the main issue was here - missing break after this line. I decided to simplify code though.

}
}
_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"));
}
}
}