Skip to content

Commit 3bd09a7

Browse files
hempelsbastianeicher
authored andcommitted
Tolerate 0-value (missing) local size headers.
Some rogue zip creators fail to set a non-zero local header size in Extra Data causing SharpZLib to reject them, this patch causes the library to tolerate that particular oversight like most other libraries.
1 parent aba4dce commit 3bd09a7

File tree

1 file changed

+5
-4
lines changed

1 file changed

+5
-4
lines changed

ICSharpCode.SharpZipLib/Zip/ZipFile.cs

+5-4
Original file line numberDiff line numberDiff line change
@@ -1194,16 +1194,17 @@ long TestLocalHeader(ZipEntry entry, HeaderTest tests)
11941194
// Size can be verified only if it is known in the local header.
11951195
// it will always be known in the central header.
11961196
if (((localFlags & (int)GeneralBitFlags.Descriptor) == 0) ||
1197-
((size > 0) || (compressedSize > 0))) {
1197+
((size > 0 || compressedSize > 0) && entry.Size > 0)) {
11981198

1199-
if (size != entry.Size) {
1199+
if ((size != 0)
1200+
&& (size != entry.Size)) {
12001201
throw new ZipException(
12011202
string.Format("Size mismatch between central header({0}) and local header({1})",
12021203
entry.Size, size));
12031204
}
12041205

1205-
if (compressedSize != entry.CompressedSize &&
1206-
compressedSize != 0xFFFFFFFF && compressedSize != -1) {
1206+
if ((compressedSize != 0)
1207+
&& (compressedSize != entry.CompressedSize && compressedSize != 0xFFFFFFFF && compressedSize != -1)) {
12071208
throw new ZipException(
12081209
string.Format("Compressed size mismatch between central header({0}) and local header({1})",
12091210
entry.CompressedSize, compressedSize));

0 commit comments

Comments
 (0)