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

Fix issue 20287 - std.zip: Wrong compressed data #7221

Merged
merged 1 commit into from Oct 10, 2019
Merged
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
26 changes: 25 additions & 1 deletion std/zip.d
Original file line number Diff line number Diff line change
Expand Up @@ -723,7 +723,11 @@ public:
de.comment = cast(string)(_data[i .. i + commentlen]);
i += commentlen;

immutable uint dataOffset = de.offset + localFileHeaderLength + namelen + extralen;
auto localFileHeaderNamelen = getUshort(de.offset + 26);
auto localFileHeaderExtralen = getUshort(de.offset + 28);

immutable uint dataOffset = de.offset + localFileHeaderLength
+ localFileHeaderNamelen + localFileHeaderExtralen;
if (dataOffset + de.compressedSize > endrecOffset)
throw new ZipException("Invalid directory entry offset or size.");
de._compressedData = _data[dataOffset .. dataOffset + de.compressedSize];
Expand Down Expand Up @@ -1150,6 +1154,26 @@ the quick brown fox jumps over the lazy dog\r
assertThrown!ZipException(new ZipArchive(cast(void[]) file));
}

@system unittest
{
// issue #20287: check for correct compressed data
auto file =
"\x50\x4b\x03\x04\x0a\x00\x00\x00\x00\x00\x8f\x72\x4a\x4f\x86\xa6"~
"\x10\x36\x05\x00\x00\x00\x05\x00\x00\x00\x04\x00\x1c\x00\x66\x69"~
"\x6c\x65\x55\x54\x09\x00\x03\x0d\x22\x9f\x5d\x12\x22\x9f\x5d\x75"~
"\x78\x0b\x00\x01\x04\xf0\x03\x00\x00\x04\xf0\x03\x00\x00\x68\x65"~
"\x6c\x6c\x6f\x50\x4b\x01\x02\x1e\x03\x0a\x00\x00\x00\x00\x00\x8f"~
"\x72\x4a\x4f\x86\xa6\x10\x36\x05\x00\x00\x00\x05\x00\x00\x00\x04"~
"\x00\x18\x00\x00\x00\x00\x00\x01\x00\x00\x00\xb0\x81\x00\x00\x00"~
"\x00\x66\x69\x6c\x65\x55\x54\x05\x00\x03\x0d\x22\x9f\x5d\x75\x78"~
"\x0b\x00\x01\x04\xf0\x03\x00\x00\x04\xf0\x03\x00\x00\x50\x4b\x05"~
"\x06\x00\x00\x00\x00\x01\x00\x01\x00\x4a\x00\x00\x00\x43\x00\x00"~
"\x00\x00\x00";

auto za = new ZipArchive(cast(void[]) file);
assert(za.directory["file"].compressedData == [104, 101, 108, 108, 111]);
}

// Non-Android Posix-only, because we can't rely on the unzip command being
// available on Android or Windows
version (Android) {} else
Expand Down