]> Cypherpunks repositories - gostls13.git/commit
archive/zip: reduce CPU usage in index construction
authorDamien Neil <dneil@google.com>
Wed, 5 Nov 2025 01:00:33 +0000 (17:00 -0800)
committerGopher Robot <gobot@golang.org>
Thu, 15 Jan 2026 18:35:56 +0000 (10:35 -0800)
commitbb7c0c717c8b3517210dce8f38cb2c91694af4e2
treee97f7849dea3ecd44002c595c13d3d6d14cf7ca4
parent2dcaaa751295597e1f603b7488c4624db6a84d2b
archive/zip: reduce CPU usage in index construction

Constructing the zip index (which is done once when first opening
a file in an archive) can consume large amounts of CPU when
processing deeply-nested directory paths.

Switch to a less inefficient algorithm.

Thanks to Jakub Ciolek for reporting this issue.

goos: darwin
goarch: arm64
pkg: archive/zip
cpu: Apple M4 Pro
                          │  /tmp/bench.0  │            /tmp/bench.1            │
                          │     sec/op     │   sec/op     vs base               │
ReaderOneDeepDir-14         25983.62m ± 2%   46.01m ± 2%  -99.82% (p=0.000 n=8)
ReaderManyDeepDirs-14          16.221 ± 1%    2.763 ± 6%  -82.96% (p=0.000 n=8)
ReaderManyShallowFiles-14      130.3m ± 1%   128.8m ± 2%   -1.20% (p=0.003 n=8)
geomean                         3.801        253.9m       -93.32%

Fixes #77102
Fixes CVE-2025-61728

Change-Id: I2c9c864be01b2a2769eb67fbab1b250aeb8f6c42
Reviewed-on: https://go-internal-review.googlesource.com/c/go/+/3060
Reviewed-by: Nicholas Husin <husin@google.com>
Reviewed-by: Neal Patel <nealpatel@google.com>
Reviewed-on: https://go-review.googlesource.com/c/go/+/736713
Auto-Submit: Michael Pratt <mpratt@google.com>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Reviewed-by: Junyang Shao <shaojunyang@google.com>
src/archive/zip/reader.go
src/archive/zip/reader_test.go