Skip to content

Commit b7ebd22

Browse files
committed
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 5f57a54 commit b7ebd22

1 file changed

Lines changed: 5 additions & 4 deletions

File tree

src/Zip/ZipFile.cs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1249,16 +1249,17 @@ long TestLocalHeader(ZipEntry entry, HeaderTest tests)
12491249
// Size can be verified only if it is known in the local header.
12501250
// it will always be known in the central header.
12511251
if (((localFlags & (int)GeneralBitFlags.Descriptor) == 0) ||
1252-
((size > 0) || (compressedSize > 0))) {
1252+
((size > 0 || compressedSize > 0) && entry.Size > 0)) {
12531253

1254-
if (size != entry.Size) {
1254+
if ((size != 0)
1255+
&& (size != entry.Size)) {
12551256
throw new ZipException(
12561257
string.Format("Size mismatch between central header({0}) and local header({1})",
12571258
entry.Size, size));
12581259
}
12591260

1260-
if (compressedSize != entry.CompressedSize &&
1261-
compressedSize != 0xFFFFFFFF && compressedSize != -1) {
1261+
if ((compressedSize != 0)
1262+
&& (compressedSize != entry.CompressedSize && compressedSize != 0xFFFFFFFF && compressedSize != -1)) {
12621263
throw new ZipException(
12631264
string.Format("Compressed size mismatch between central header({0}) and local header({1})",
12641265
entry.CompressedSize, compressedSize));

0 commit comments

Comments
 (0)