Find zip file end of central directory backwards up to max possible size (dotnet...
authorCarlos Sanchez Lopez <1175054+carlossanlop@users.noreply.github.com>
Mon, 30 Sep 2019 17:46:27 +0000 (10:46 -0700)
committerGitHub <noreply@github.com>
Mon, 30 Sep 2019 17:46:27 +0000 (10:46 -0700)
commit04ef09857c4c805b297b739f60fae08bb4d42095
tree9c16c27749ea2add9e7847169ad2b1e8864c5dee
parente17c64109d5de8edcb9cb4d22434d546b65d2bf6
Find zip file end of central directory backwards up to max possible size (dotnet/corefx#41007)

Issue
Huge zip files without an end of central directory take a long time to throw because we seek to the end then search backwards for the EOCD signature all the way to the end.

Fix
Ensure we only search for the signature from the end within the maximum possible number of bytes where it can be found. If the signature is not found, we fail faster.

Note
This may be a breaking change for the edge case where a zip file contains an EOCD comment with the maximum length + additional trailing garbage.

Commit migrated from https://github.com/dotnet/corefx/commit/9d9c06f82eb4675a2aa56f07fe55a78039147784
src/libraries/System.IO.Compression/src/System/IO/Compression/ZipArchive.cs
src/libraries/System.IO.Compression/src/System/IO/Compression/ZipBlocks.cs
src/libraries/System.IO.Compression/src/System/IO/Compression/ZipHelper.cs
src/libraries/System.IO.Compression/tests/ZipArchive/zip_InvalidParametersAndStrangeFiles.cs