]> Cypherpunks repositories - gostls13.git/commit
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)
committerDamien Neil <dneil@google.com>
Tue, 25 May 2021 23:41:42 +0000 (23:41 +0000)
commit74242baa4136c7a9132a8ccd9881354442788c8c
tree651391bbad1571977491c6deea836e0339cf3f27
parentf22ec51debeddc0903096e66bfaf641568bede3b
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.

Fixes #46242
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>
src/archive/zip/reader.go
src/archive/zip/reader_test.go