Commit 895fb1bb authored by Roland Shoemaker's avatar Roland Shoemaker Committed by Katie Hockman
Browse files

[release-branch.go1.16] archive/zip: only preallocate File slice if reasonably sized

Since the number of files in the EOCD record isn't validated, it isn't
safe to preallocate Reader.Files using that field. A malformed archive
can indicate it contains up to 1 << 128 - 1 files. We can still safely
preallocate the slice by checking if the specified number of files in
the archive is reasonable, given the size of the archive.

Thanks to the OSS-Fuzz project for discovering this issue and to
Emmanuel Odeke for reporting it.

Updates #46242
Fixes #46397
Fixes CVE-2021-33196

Change-Id: I3c76d8eec178468b380d87fdb4a3f2cb06f0ee76
Reviewed-on: https://go-review.googlesource.com/c/go/+/318909


Trust: Roland Shoemaker <roland@golang.org>
Trust: Katie Hockman <katie@golang.org>
Trust: Joe Tsai <thebrokentoaster@gmail.com>
Run-TryBot: Roland Shoemaker <roland@golang.org>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: default avatarKatie Hockman <katie@golang.org>
Reviewed-by: default avatarJoe Tsai <thebrokentoaster@gmail.com>
(cherry picked from commit 74242baa)
Reviewed-on: https://go-review.googlesource.com/c/go/+/322909


Reviewed-by: default avatarFilippo Valsorda <filippo@golang.org>
parent df6a737c
Loading
Loading
Loading
Loading
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please to comment