]> Cypherpunks repositories - gostls13.git/commit
[release-branch.go1.16] archive/zip: only preallocate File slice if reasonably sized
authorRoland Shoemaker <roland@golang.org>
Tue, 11 May 2021 18:31:31 +0000 (11:31 -0700)
committerKatie Hockman <katie@golang.org>
Fri, 28 May 2021 13:53:29 +0000 (13:53 +0000)
commit895fb1bb6fc0d3c01c5ef7c8cbaf033d1fff9ad7
tree9a3acb79e69d46c8ce12afe9ecaaf4975c0e63ca
parentdf6a737cc899507d3090e995abd1e1ed1a30cee3
[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: Katie Hockman <katie@golang.org>
Reviewed-by: Joe Tsai <thebrokentoaster@gmail.com>
(cherry picked from commit 74242baa4136c7a9132a8ccd9881354442788c8c)
Reviewed-on: https://go-review.googlesource.com/c/go/+/322909
Reviewed-by: Filippo Valsorda <filippo@golang.org>
src/archive/zip/reader.go
src/archive/zip/reader_test.go