aboutsummaryrefslogtreecommitdiff
path: root/src/archive/zip
AgeCommit message (Collapse)Author
41 hoursall: prealloc slice with possible minimum capabilitiesShulhan
2026-01-15archive/zip: reduce CPU usage in index constructionDamien Neil
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>
2025-10-17all: remove unnecessary loop variable copies in testsTobias Klauser
Copying the loop variable is no longer necessary since Go 1.22. Change-Id: Iebb21dac44a20ec200567f1d786f105a4ee4999d Reviewed-on: https://go-review.googlesource.com/c/go/+/711640 Reviewed-by: Florian Lehner <lehner.florian86@gmail.com> Auto-Submit: Damien Neil <dneil@google.com> Reviewed-by: Dmitri Shuralyov <dmitshur@google.com> Reviewed-by: Damien Neil <dneil@google.com> Auto-Submit: Tobias Klauser <tobias.klauser@gmail.com> LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
2025-03-11archive/zip: error on ReadDir if there are invalid file namesSean Liao
Fixes #50179 Change-Id: I616a6d1279d025e345d2daa6d44b687c8a2d09e1 Reviewed-on: https://go-review.googlesource.com/c/go/+/656495 LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> Auto-Submit: Ian Lance Taylor <iant@google.com> Reviewed-by: David Chase <drchase@google.com> Reviewed-by: Ian Lance Taylor <iant@google.com>
2025-03-07archive/zip: preallocate fileList size for Reader.OpenOlivier Mengué
When building the index of file entries for Reader.Open (when the Reader is used as an io/fs.FS), reduce reallocations by pre-allocating the count of entries based on the count of file entries. Change-Id: I05048337cb5e752054b3e984a8a5ec5199c4589b Reviewed-on: https://go-review.googlesource.com/c/go/+/655476 LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> Reviewed-by: Ian Lance Taylor <iant@google.com> Reviewed-by: Junyang Shao <shaojunyang@google.com> Auto-Submit: Ian Lance Taylor <iant@golang.org>
2025-01-27archive/zip, archive/tar: writer appends slash to directory namesyincong
Fixes #71235 Change-Id: I62aebb9d421db0e4b57ad5cae25c70f47aa5f8f9 GitHub-Last-Rev: 6e0fba07dd128e20e32a3a6258edf80ee91d4690 GitHub-Pull-Request: golang/go#71239 Reviewed-on: https://go-review.googlesource.com/c/go/+/642375 Reviewed-by: Jonathan Amsterdam <jba@google.com> LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> Reviewed-by: Ian Lance Taylor <iant@google.com> Auto-Submit: Ian Lance Taylor <iant@google.com> Commit-Queue: Ian Lance Taylor <iant@google.com>
2024-09-23archive/{zip,tar}: fix Writer.AddFS to include empty directoriesSong Gao
This change modifies the `(*Writer).AddFS` implementation in both `archive/zip` and `archive/tar` to always write a directory header. This fixes a bug where any empty directories in the fs were omitted when a zip or tar archive was created from `AddFS` method. Fixes #66831 Change-Id: Id32c9c747f9f65ec7db4aeefeaffa83567215bfc Reviewed-on: https://go-review.googlesource.com/c/go/+/578415 Auto-Submit: Ian Lance Taylor <iant@google.com> Reviewed-by: Ian Lance Taylor <iant@google.com> Reviewed-by: Carlos Amedee <carlos@golang.org> LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
2024-08-03archive/zip,cmd/compile: simplify the split functionapocelipes
Use strings to simplify the code. This is a follow-up for the CL 586715. Change-Id: I9e5470ec271e8af1ad4ddbb5f01f43a8a4879557 GitHub-Last-Rev: b95d6179781053ea8ec9fc8ad2e18607fd35c5bb GitHub-Pull-Request: golang/go#68713 Reviewed-on: https://go-review.googlesource.com/c/go/+/602697 LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> Auto-Submit: Ian Lance Taylor <iant@google.com> Reviewed-by: Michael Knyszek <mknyszek@google.com> Reviewed-by: Ian Lance Taylor <iant@google.com>
2024-07-25archive: use slices and maps to clean up testsapocelipes
Replace reflect.DeepEqual with slices.Equal/maps.Equal, which is much faster. Clean up some unnecessary helper functions. Change-Id: I9b94bd43886302b9b327539ab065a435ce0d75d9 GitHub-Last-Rev: b9ca21f165bcc5e45733e6a511a2344b1aa4a281 GitHub-Pull-Request: golang/go#67607 Reviewed-on: https://go-review.googlesource.com/c/go/+/587936 LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> Reviewed-by: Ian Lance Taylor <iant@google.com> Reviewed-by: Dmitri Shuralyov <dmitshur@google.com> Auto-Submit: Ian Lance Taylor <iant@google.com> Reviewed-by: Joseph Tsai <joetsai@digital-static.net>
2024-07-16archive/zip: document handling of duplicate names in Writer.CreateSean Liao
Fixes #66810 Change-Id: I6a7848dce245ae14941d61d2f78abaf0dc5c1247 Reviewed-on: https://go-review.googlesource.com/c/go/+/597978 LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> Reviewed-by: Cherry Mui <cherryyz@google.com> Reviewed-by: Ian Lance Taylor <iant@google.com> Auto-Submit: Ian Lance Taylor <iant@google.com>
2024-05-28archive/zip: fix UncompressedSize godocRTann
Change-Id: I0c142eb18af7b03759041e894bbce0f365ea9d7e Reviewed-on: https://go-review.googlesource.com/c/go/+/588116 LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> Reviewed-by: Dmitri Shuralyov <dmitshur@google.com> Auto-Submit: Ian Lance Taylor <iant@google.com> Reviewed-by: Ian Lance Taylor <iant@google.com>
2024-05-23all: change from sort functions to slices functions where feasibleIan Lance Taylor
Doing this because the slices functions are slightly faster and slightly easier to use. It also removes one dependency layer. This CL does not change packages that are used during bootstrap, as the bootstrap compiler does not have the required slices functions. It does not change the go/scanner package because the ErrorList Len, Swap, and Less methods are part of the Go 1 API. Change-Id: If52899be791c829198e11d2408727720b91ebe8a Reviewed-on: https://go-review.googlesource.com/c/go/+/587655 LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> Reviewed-by: Ian Lance Taylor <iant@google.com> Auto-Submit: Ian Lance Taylor <iant@google.com> Commit-Queue: Ian Lance Taylor <iant@google.com> Reviewed-by: Damien Neil <dneil@google.com>
2024-05-16archive/zip: treat truncated EOCDR comment as an errorDamien Neil
When scanning for an end of central directory record, treat an EOCDR signature with a record containing a truncated comment as an error. Previously, we would skip over the invalid record and look for another one. Other implementations do not do this (they either consider this a hard error, or just ignore the truncated comment). This parser misalignment allowed presenting entirely different archive contents to Go programs and other zip decoders. Fixes #66869 Change-Id: I94e5cb028534bb5704588b8af27f1e22ea49c7c6 Reviewed-on: https://go-review.googlesource.com/c/go/+/585397 Reviewed-by: Joseph Tsai <joetsai@digital-static.net> Reviewed-by: Dmitri Shuralyov <dmitshur@google.com> LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
2024-04-04archive/zip: fix a broken URL in a comment in writeDataDescriptorLiam Miller-Cushon
The comment contains a dead link to a OpenJDK bug ID 7073588 this change fixes the link. Change-Id: Ib9b10362c707507e59bb6f340d52a0025f65e292 GitHub-Last-Rev: 37af15b947a59346e23191dad264efa0aaa461af GitHub-Pull-Request: golang/go#66669 Reviewed-on: https://go-review.googlesource.com/c/go/+/576335 Auto-Submit: Ian Lance Taylor <iant@google.com> Reviewed-by: Dmitri Shuralyov <dmitshur@google.com> LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> Reviewed-by: Ian Lance Taylor <iant@google.com>
2024-03-27all: make use of builtin clearJes Cok
Change-Id: I1df0685c75fc1044ba46003a69ecc7dfc53bbc2b Reviewed-on: https://go-review.googlesource.com/c/go/+/574675 Reviewed-by: Ian Lance Taylor <iant@google.com> Reviewed-by: Than McIntosh <thanm@google.com> LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> Auto-Submit: Ian Lance Taylor <iant@google.com>
2024-02-06archive/zip: reduce memory held by Writer.CopyJonathan Amsterdam
Make a copy of the argument File's FileHeader, and pass a pointer to the copy to CreateRaw. Passing the pointer directly causes the entire `File` to be referenced by the receiver. The `File` includes a reference to the `ReaderAt` underlying the `Reader`, so all its memory, which may be the entire contents of the archive, is prevented from being garbage-collected. Also, explain the issue in the doc comment for CreateRaw. We cannot change its behavior because someone may depend on the preserving the identity of its argument pointer. For #65499. Change-Id: Ieb4963a0ea30539d597547d3511accbd8c6b5c5a Reviewed-on: https://go-review.googlesource.com/c/go/+/560238 LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> Reviewed-by: Damien Neil <dneil@google.com>
2023-10-13archive: add available godoc linkcui fliter
Change-Id: I813aa09f8a65936796469fa637d0f23004d26098 Reviewed-on: https://go-review.googlesource.com/c/go/+/534757 Reviewed-by: Dmitri Shuralyov <dmitshur@google.com> TryBot-Result: Gopher Robot <gobot@golang.org> Auto-Submit: Ian Lance Taylor <iant@golang.org> Reviewed-by: Joseph Tsai <joetsai@digital-static.net> Reviewed-by: Ian Lance Taylor <iant@google.com> Run-TryBot: shuang cui <imcusg@gmail.com>
2023-09-25all: use the indefinite article an in commentsJes Cok
Change-Id: I8787458f9ccd3b5cdcdda820d8a45deb4f77eade GitHub-Last-Rev: be865d67ef68815b8c1c2a9ad222fff594620e66 GitHub-Pull-Request: golang/go#63165 Reviewed-on: https://go-review.googlesource.com/c/go/+/530120 LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> Reviewed-by: Ian Lance Taylor <iant@google.com> Auto-Submit: Ian Lance Taylor <iant@google.com> Reviewed-by: Than McIntosh <thanm@google.com>
2023-09-22all: clean unnecessary casts for test filesJes Cok
This is a follow up of CL 528696. Change-Id: I5b71eabedb12567c4b1b36f7182a3d2b0ed662a5 GitHub-Last-Rev: acaf3ac11c38042ad27b99e1c70a3c9f1a554a15 GitHub-Pull-Request: golang/go#62713 Reviewed-on: https://go-review.googlesource.com/c/go/+/529197 Reviewed-by: Ian Lance Taylor <iant@google.com> Auto-Submit: Ian Lance Taylor <iant@google.com> Reviewed-by: Matthew Dempsky <mdempsky@google.com> LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
2023-09-18all: clean unnecessary castsJes Cok
Run 'unconvert -safe -apply' (https://github.com/mdempsky/unconvert) Change-Id: I24b7cd7d286cddce86431d8470d15c5f3f0d1106 GitHub-Last-Rev: 022e75384c08bb899a8951ba0daffa0f2e14d5a7 GitHub-Pull-Request: golang/go#62662 Reviewed-on: https://go-review.googlesource.com/c/go/+/528696 Auto-Submit: Ian Lance Taylor <iant@google.com> LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> Reviewed-by: Ian Lance Taylor <iant@google.com> Reviewed-by: Michael Pratt <mpratt@google.com>
2023-09-15archive/zip: reject non-regular files in AddFSMauri de Souza Meneguzzo
When a filesystem with non-regular files is used the resulting files inside the zip archive are empty. In this case we can be explicit and return an error. Fixes #61875 Change-Id: I1aeac544521002e0c4bad328e73f51852ad4eee3 GitHub-Last-Rev: 5e53dcfd7c12e45d4142016d0b9b286f9aa83d56 GitHub-Pull-Request: golang/go#61876 Reviewed-on: https://go-review.googlesource.com/c/go/+/517475 Auto-Submit: Ian Lance Taylor <iant@golang.org> Run-TryBot: Mauri de Souza Meneguzzo <mauri870@gmail.com> TryBot-Result: Gopher Robot <gobot@golang.org> Reviewed-by: Bryan Mills <bcmills@google.com> Reviewed-by: David Chase <drchase@google.com>
2023-09-12all: fix Microsoft linksqmuntal
This CL fixes the links to Microsoft documentation in the Go source code. Some links were broken and some others were outdated. Change-Id: I4c3bcd3aa3c07a31be1b7f94c25339dcc2e771e8 Reviewed-on: https://go-review.googlesource.com/c/go/+/527556 Reviewed-by: Heschi Kreinick <heschi@google.com> Reviewed-by: Ian Lance Taylor <iant@google.com> TryBot-Result: Gopher Robot <gobot@golang.org> LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> Run-TryBot: Quim Muntal <quimmuntal@gmail.com> Auto-Submit: Quim Muntal <quimmuntal@gmail.com>
2023-08-30archive/zip: update link to zip specificationYusuf Birader
Change-Id: Iad902ec2a13b0c5c594c60ecac0b40f641574a1e Reviewed-on: https://go-review.googlesource.com/c/go/+/524275 Reviewed-by: Ian Lance Taylor <iant@google.com> TryBot-Result: Gopher Robot <gobot@golang.org> Reviewed-by: Dmitri Shuralyov <dmitshur@google.com> Reviewed-by: Joseph Tsai <joetsai@digital-static.net> Run-TryBot: Joseph Tsai <joetsai@digital-static.net> LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> Auto-Submit: Ian Lance Taylor <iant@google.com>
2023-08-03archive: use predeclared function minqiulaidongfeng
Change-Id: I23e0005071fcbafeaecaa05f51712dd1de6eed01 Change-Id: I23e0005071fcbafeaecaa05f51712dd1de6eed01 GitHub-Last-Rev: 364d7c74fef1668930b730b05a7539f7ac43e60a GitHub-Pull-Request: golang/go#61661 Reviewed-on: https://go-review.googlesource.com/c/go/+/514215 TryBot-Result: Gopher Robot <gobot@golang.org> Auto-Submit: Ian Lance Taylor <iant@google.com> Reviewed-by: David Chase <drchase@google.com> Run-TryBot: Ian Lance Taylor <iant@golang.org> Reviewed-by: Ian Lance Taylor <iant@google.com> Run-TryBot: Ian Lance Taylor <iant@google.com>
2023-07-31archive/zip: add AddFS method to zip WriterMauri de Souza Meneguzzo
The method AddFS can be used to add the contents of a fs.FS filesystem to a zip archive. This method walks the directory tree starting at the root of the filesystem and adds each file to the archive. Fixes #54898 Change-Id: I80511cbd91a1d7e09ee52d2d1b09fb5eed25f45f GitHub-Last-Rev: 1e17f2e6bae60cf5168d687dd1357ab58a883675 GitHub-Pull-Request: golang/go#61602 Reviewed-on: https://go-review.googlesource.com/c/go/+/513438 Reviewed-by: David Chase <drchase@google.com> TryBot-Result: Gopher Robot <gobot@golang.org> Auto-Submit: Ian Lance Taylor <iant@google.com> Reviewed-by: Ian Lance Taylor <iant@google.com> Run-TryBot: Ian Lance Taylor <iant@golang.org> Run-TryBot: Ian Lance Taylor <iant@google.com>
2023-05-24compress/flate, archive/zip: reduce memory allocationsMaksim Meshkov
The existing implementation allocates a new 4KB buffer each time it opens flate-encoded file in a zip archive. This commit allows the flate reader to reuse the buffer on call Reset instead of allocating a new one. It is noticeable when a zip archive contains a huge amount of files, e.g. zip archive has 50_000 files, for each file 4KB buffer is allocated, so it is 200MB memory allocations. If files are read sequentially only one buffer is needed. Fixes #59774 Change-Id: Ib16336b101ba58e8f0f30a45dc5fd4eeebc801a1 GitHub-Last-Rev: f3f395b2ad95b7ad7ce9df6f5e49c7b6a0627627 GitHub-Pull-Request: golang/go#59775 Reviewed-on: https://go-review.googlesource.com/c/go/+/487675 Run-TryBot: Ian Lance Taylor <iant@golang.org> Auto-Submit: Ian Lance Taylor <iant@google.com> Run-TryBot: Ian Lance Taylor <iant@google.com> TryBot-Result: Gopher Robot <gobot@golang.org> Reviewed-by: Ian Lance Taylor <iant@google.com> Reviewed-by: Matthew Dempsky <mdempsky@google.com>
2023-05-04all: add String for fs.{FileInfo,DirEntry} implementationsIan Lance Taylor
The new String methods use the new FormatFileInfo and FormatDirEntry functions. Fixes #54451 Change-Id: I414cdfc212ec3c316fb2734756d2117842a23631 Reviewed-on: https://go-review.googlesource.com/c/go/+/491175 Reviewed-by: Joseph Tsai <joetsai@digital-static.net> Run-TryBot: Ian Lance Taylor <iant@golang.org> TryBot-Result: Gopher Robot <gobot@golang.org> Reviewed-by: Ian Lance Taylor <iant@google.com> Run-TryBot: Ian Lance Taylor <iant@google.com> Auto-Submit: Ian Lance Taylor <iant@google.com> Reviewed-by: Bryan Mills <bcmills@google.com>
2023-04-24archive/zip: reject overflowing directorySize & directoryOffsetRoland Shoemaker
We added a check for incorrect baseOffset in CL 408734, but in doing so we introduced a panic when directoryOffset overflowed a int64. The zip spec uses uint64, but since io.SectionReader requires int64 we convert, and possibly introduce an overflow. If offset < 0 && size-offset < 0, SectionReader will panic when we attempt to read from it. Since it's extremely unlikely we're ever going to process a zip file larger than 1<<63-1 byte, just limit directory size and offset to the max int64. Change-Id: I1aaa755cf4da927a6e12ef59f97dfc83a3426d86 Reviewed-on: https://go-review.googlesource.com/c/go/+/488195 Reviewed-by: Ian Lance Taylor <iant@google.com> Run-TryBot: Roland Shoemaker <roland@golang.org> TryBot-Result: Gopher Robot <gobot@golang.org> Auto-Submit: Roland Shoemaker <roland@golang.org>
2023-04-05archive/zip: return ErrInsecurePath for unsafe paths by OpenReaderImre Rad
zip.NewReader was recently improved to return ErrInsecurePath when insecure entries are encountered. This change adopts the same logic for the OpenReader interface as well. Fixes #58641 Change-Id: I0d8be94d073cc14cf93a914dc250f85b19cec4ab GitHub-Last-Rev: 68391dc51562aebc893ec70fdfbdfb181955983a GitHub-Pull-Request: golang/go#58658 Reviewed-on: https://go-review.googlesource.com/c/go/+/470735 Run-TryBot: Damien Neil <dneil@google.com> TryBot-Result: Gopher Robot <gobot@golang.org> Reviewed-by: Damien Neil <dneil@google.com> Reviewed-by: Dmitri Shuralyov <dmitshur@google.com> Auto-Submit: Damien Neil <dneil@google.com>
2023-04-04all: fix misuses of "a" vs "an"cui fliter
Fixes the misuse of "a" vs "an", according to English grammatical expectations and using https://www.a-or-an.com/ Change-Id: I53ac724070e3ff3d33c304483fe72c023c7cda47 Reviewed-on: https://go-review.googlesource.com/c/go/+/480536 Run-TryBot: shuang cui <imcusg@gmail.com> Reviewed-by: Ian Lance Taylor <iant@google.com> TryBot-Result: Gopher Robot <gobot@golang.org> Auto-Submit: Ian Lance Taylor <iant@google.com> Run-TryBot: Ian Lance Taylor <iant@google.com> Reviewed-by: Michael Knyszek <mknyszek@google.com>
2023-03-02archive/zip: make receiver names consistentOleksandr Redko
Fixes revive linter receiver-naming warnings: - receiver name f should be consistent with previous receiver name e for fileListEntry - receiver name r should be consistent with previous receiver name z for Reader - receiver name f should be consistent with previous receiver name h for FileHeader Change-Id: Ibfa14b97f6ca7adc86e3a1df919c5bb5de9716dc GitHub-Last-Rev: dd7315b09d224bb2953b82cc6bd97d81c9eaca0a GitHub-Pull-Request: golang/go#58477 Reviewed-on: https://go-review.googlesource.com/c/go/+/467519 Run-TryBot: Ian Lance Taylor <iant@golang.org> Auto-Submit: Ian Lance Taylor <iant@google.com> Reviewed-by: Joseph Tsai <joetsai@digital-static.net> Reviewed-by: Dmitri Shuralyov <dmitshur@google.com> Reviewed-by: Ian Lance Taylor <iant@google.com> TryBot-Bypass: Ian Lance Taylor <iant@google.com>
2023-01-20archive/zip: use base offset 0 if it has a valid entryIan Lance Taylor
In CL 408734 we introduced a fall back to base offset 0 if reading a directory entry at the computed base offset failed. We have now found a file in the wild for which the computed base offset is incorrect, but happens to refer to a valid directory entry. In this CL, we change the fallback such that if the first directory header relative to base offset 0 is valid, we just use base offset 0. Change-Id: Ia9ace20c1065d1f651035f16f7d91d741ab1dbf4 Reviewed-on: https://go-review.googlesource.com/c/go/+/461598 Reviewed-by: Cherry Mui <cherryyz@google.com> TryBot-Result: Gopher Robot <gobot@golang.org> Reviewed-by: Ian Lance Taylor <iant@google.com> Auto-Submit: Ian Lance Taylor <iant@google.com> Reviewed-by: Joseph Tsai <joetsai@digital-static.net> Run-TryBot: Ian Lance Taylor <iant@golang.org> Run-TryBot: Ian Lance Taylor <iant@google.com>
2023-01-19internal/godebug: export non-default-behavior counters in runtime/metricsRuss Cox
Allow GODEBUG users to report how many times a setting resulted in non-default behavior. Record non-default-behaviors for all existing GODEBUGs. Also rework tests to ensure that runtime is in sync with runtime/metrics.All, and generate docs mechanically from metrics.All. For #56986. Change-Id: Iefa1213e2a5c3f19ea16cd53298c487952ef05a4 Reviewed-on: https://go-review.googlesource.com/c/go/+/453618 TryBot-Result: Gopher Robot <gobot@golang.org> Auto-Submit: Russ Cox <rsc@golang.org> Run-TryBot: Russ Cox <rsc@golang.org> Reviewed-by: Michael Knyszek <mknyszek@google.com>
2023-01-17archive/tar, archive/zip: document ErrInsecurePath and GODEBUG settingRuss Cox
These are mentioned in the release notes but not the actual doc comments. Nothing should exist only in release notes. Change-Id: I8d10f25a2c9b2677231929ba3f393af9034b777b Reviewed-on: https://go-review.googlesource.com/c/go/+/462195 Run-TryBot: Russ Cox <rsc@golang.org> Reviewed-by: Damien Neil <dneil@google.com> TryBot-Result: Gopher Robot <gobot@golang.org>
2022-12-21archive/tar, archive/zip: revert documentation of ErrInsecurePathDamien Neil
CL 452616 disables path security checks by default, enabling them only when GODEBUG=tarinsecurepath=0 or GODEBUG=zipinsecurepath=0 is set. Remove now-obsolete documenation of the path checks. For #55356 Change-Id: I4ae57534efe9e27368d5e67773a502dd0e56eff4 Reviewed-on: https://go-review.googlesource.com/c/go/+/458875 Reviewed-by: Russ Cox <rsc@golang.org> TryBot-Result: Gopher Robot <gobot@golang.org> Run-TryBot: Damien Neil <dneil@google.com>
2022-12-06archive/zip: only consider UncompressedSize when checking dirsRoland Shoemaker
CL 454475 switched from checking CompressedSize to UncompressedSize when determining if we should consider an archive malformed because it contains data and added a test for an example of this (a JAR). We should also remove the hasDataDescriptor check, since that is basically an alias for CompressedSize > 0. The test didn't catch this because we didn't actually attempt to read from the returned reader. Change-Id: Ibc4c1aa9c3a733f3ebf4a956d1e2f8f4900a29cd Reviewed-on: https://go-review.googlesource.com/c/go/+/455523 Run-TryBot: Roland Shoemaker <roland@golang.org> Reviewed-by: Julie Qiu <julieqiu@google.com> Auto-Submit: Roland Shoemaker <roland@golang.org> TryBot-Result: Gopher Robot <gobot@golang.org>
2022-12-02archive/zip: use proper doc comment for Deprecated notesRuss Cox
End-of-line comments are not doc comments, so Deprecated notes in them are not recognized as deprecation notices. Rewrite the comments. Change-Id: Idc4681924f9a7e9ead62f672ef8a763e70db1f0f Reviewed-on: https://go-review.googlesource.com/c/go/+/453616 TryBot-Result: Gopher Robot <gobot@golang.org> Reviewed-by: Joseph Tsai <joetsai@digital-static.net> Reviewed-by: Ian Lance Taylor <iant@google.com> Run-TryBot: Russ Cox <rsc@golang.org> Auto-Submit: Russ Cox <rsc@golang.org>
2022-12-01archive/zip: tolerate compressed directories with zero uncompressed sizeRoland Shoemaker
In CL 449955 we made reading of directories with associated file data an error, since it is a "must not" in the zip specification. It turns out that a number of implementations make the mistake of not setting the correct compression method on directories (in particular the Java jar tool does this when storing the META-INF directory). If the compression method used is not 0 (stored) then the compressed size of the directory can be > 0, despite the uncompressed size still being 0. Since this mistake is not uncommon, we are forced to tolerate it. We still fail if the recorded uncompressed size is > 0, which should be a significantly harder mistake to make. Change-Id: Ia732b10787f26ab937ac9cf9869ac3042efb8118 Reviewed-on: https://go-review.googlesource.com/c/go/+/454475 Reviewed-by: Ian Lance Taylor <iant@google.com> Auto-Submit: Roland Shoemaker <roland@golang.org> TryBot-Result: Gopher Robot <gobot@golang.org> Run-TryBot: Roland Shoemaker <roland@golang.org>
2022-11-22archive/tar, archive/zip: disable ErrInsecurePath by defaultDamien Neil
This change is being made late in the release cycle. Disable it by default. Insecure path checks may be enabled by setting GODEBUG=tarinsecurepath=0 or GODEBUG=zipinsecurepath=0. We can enable this by default in Go 1.21 after publicizing the change more broadly and giving users a chance to adapt to the change. For #55356. Change-Id: I549298b3c85d6c8c7fd607c41de1073083f79b1d Reviewed-on: https://go-review.googlesource.com/c/go/+/452616 TryBot-Result: Gopher Robot <gobot@golang.org> Auto-Submit: Damien Neil <dneil@google.com> Reviewed-by: Russ Cox <rsc@golang.org> Run-TryBot: Damien Neil <dneil@google.com>
2022-11-21archive/tar, archive/zip: disable insecure file name checks with GODEBUGDamien Neil
Add GODEBUG=tarinsecurepath=1 and GODEBUG=zipinsecurepath=1 settings to disable file name validation. For #55356. Change-Id: Iaacdc629189493e7ea3537a81660215a59dd40a4 Reviewed-on: https://go-review.googlesource.com/c/go/+/452495 Reviewed-by: Bryan Mills <bcmills@google.com> TryBot-Result: Gopher Robot <gobot@golang.org> Run-TryBot: Damien Neil <dneil@google.com> Reviewed-by: Russ Cox <rsc@golang.org> Reviewed-by: Heschi Kreinick <heschi@google.com>
2022-11-16archive/tar, archive/zip: return ErrInsecurePath for unsafe pathsDamien Neil
Return a distinguishable error when reading an archive file with a path that is: - absolute - escapes the current directory (../a) - on Windows, a reserved name such as NUL Users may ignore this error and proceed if they do not need name sanitization or intend to perform it themselves. Fixes #25849 Fixes #55356 Change-Id: Ieefa163f00384bc285ab329ea21a6561d39d8096 Reviewed-on: https://go-review.googlesource.com/c/go/+/449937 Reviewed-by: Joseph Tsai <joetsai@digital-static.net> TryBot-Result: Gopher Robot <gobot@golang.org> Run-TryBot: Damien Neil <dneil@google.com> Auto-Submit: Damien Neil <dneil@google.com> Reviewed-by: Ian Lance Taylor <iant@golang.org> Reviewed-by: Roland Shoemaker <roland@golang.org>
2022-11-14archive/zip: don't read directories containing file dataAlexander Yastrebov
Fixes #54801 Change-Id: I3d03516792975ddb09835b2621c57e12e7cbad35 GitHub-Last-Rev: 4faa7e14dcc48c05d707f1e137d915da24133e14 GitHub-Pull-Request: golang/go#56714 Reviewed-on: https://go-review.googlesource.com/c/go/+/449955 Run-TryBot: Ian Lance Taylor <iant@golang.org> TryBot-Result: Gopher Robot <gobot@golang.org> Reviewed-by: Ian Lance Taylor <iant@google.com> Run-TryBot: Ian Lance Taylor <iant@google.com> Auto-Submit: Ian Lance Taylor <iant@google.com> Reviewed-by: Joedian Reid <joedian@golang.org>
2022-09-29archive/zip: use strings.TrimPrefixcuiweixie
Change-Id: I2854b5e7b48c4c189df84cb7281b7b7de780eebd Reviewed-on: https://go-review.googlesource.com/c/go/+/435938 TryBot-Result: Gopher Robot <gobot@golang.org> Reviewed-by: Ian Lance Taylor <iant@google.com> Run-TryBot: Ian Lance Taylor <iant@google.com> Auto-Submit: Ian Lance Taylor <iant@google.com> Reviewed-by: Dmitri Shuralyov <dmitshur@google.com>
2022-09-06archive: use strings.Buildercuiweixie
Change-Id: I07e022ffc022bca6aa12165871e723db3ed83141 Reviewed-on: https://go-review.googlesource.com/c/go/+/428255 Reviewed-by: Ian Lance Taylor <iant@google.com> Auto-Submit: Ian Lance Taylor <iant@google.com> Run-TryBot: Ian Lance Taylor <iant@google.com> TryBot-Result: Gopher Robot <gobot@golang.org> Reviewed-by: Robert Griesemer <gri@google.com>
2022-06-02archive/zip: use bufio.Reset rather than NewReaderIan Lance Taylor
A clean up for CL 408734, suggested by Joe Tsai. Change-Id: Ida9db0b8d31785d5640938c286c9c6c82c27f457 Reviewed-on: https://go-review.googlesource.com/c/go/+/410154 Auto-Submit: Ian Lance Taylor <iant@google.com> Run-TryBot: Ian Lance Taylor <iant@golang.org> Reviewed-by: Ian Lance Taylor <iant@google.com> TryBot-Result: Gopher Robot <gobot@golang.org> Reviewed-by: Dmitri Shuralyov <dmitshur@google.com> Run-TryBot: Ian Lance Taylor <iant@google.com> Reviewed-by: Joseph Tsai <joetsai@digital-static.net>
2022-06-02archive/zip: if non-zero base offset fails, fall back to zeroIan Lance Taylor
This permits us to read files that earlier Go releases could read. It is also compatible with other zip programs. Change-Id: I7e2999f1073c4db5ba3f51f92681e0b149d55b3e Reviewed-on: https://go-review.googlesource.com/c/go/+/408734 Run-TryBot: Ian Lance Taylor <iant@golang.org> Run-TryBot: Ian Lance Taylor <iant@google.com> TryBot-Result: Gopher Robot <gobot@golang.org> Auto-Submit: Ian Lance Taylor <iant@google.com> Reviewed-by: Michael Knyszek <mknyszek@google.com> Reviewed-by: Ian Lance Taylor <iant@google.com>
2022-05-19all: gofmt main repoRuss Cox
Excluding vendor and testdata. CL 384268 already reformatted most, but these slipped past. The struct in the doc comment in debug/dwarf/type.go was fixed up by hand to indent the first and last lines as well. For #51082. Change-Id: Iad020f83aafd671ff58238fe491907e85923d0c7 Reviewed-on: https://go-review.googlesource.com/c/go/+/407137 Run-TryBot: Russ Cox <rsc@golang.org> TryBot-Result: Gopher Robot <gobot@golang.org> Auto-Submit: Russ Cox <rsc@golang.org> Reviewed-by: Ian Lance Taylor <iant@google.com>
2022-05-10archive/zip: error if using io/fs on zip with duplicate entriesIan Lance Taylor
Fixes #50390 Change-Id: I92787cdb3fa198ff88dcaadeccfcb49a3a6a88cf Reviewed-on: https://go-review.googlesource.com/c/go/+/374954 Reviewed-by: Heschi Kreinick <heschi@google.com> Reviewed-by: Joseph Tsai <joetsai@digital-static.net> Reviewed-by: Ian Lance Taylor <iant@google.com> Run-TryBot: Ian Lance Taylor <iant@google.com> Auto-Submit: Ian Lance Taylor <iant@google.com> TryBot-Result: Gopher Robot <gobot@golang.org>
2022-05-08archive/zip: permit zip files to have prefixesIan Lance Taylor
A Java jar file is a zip file, but it can have a prefix that is a bash script that unpacks the zip file. Most zip programs ignore such prefixes. This CL changes the archive/zip package to do the same. Fixes #10464 Fixes #51337 Change-Id: I976e9c64684644317bd21077bc5b4a2baf626ee6 Reviewed-on: https://go-review.googlesource.com/c/go/+/387976 Run-TryBot: Ian Lance Taylor <iant@google.com> Reviewed-by: Ian Lance Taylor <iant@google.com> TryBot-Result: Gopher Robot <gobot@golang.org> Run-TryBot: Ian Lance Taylor <iant@golang.org> Reviewed-by: David Chase <drchase@google.com> Reviewed-by: Joseph Tsai <joetsai@digital-static.net> Auto-Submit: Ian Lance Taylor <iant@google.com>
2022-05-03archive/zip: remove unused File.descErr fieldKale Blankenship
Found via staticcheck. Unused as of CL 357489. Change-Id: I3aa409994ba4388912ac7e7809168529a5b6e31c Reviewed-on: https://go-review.googlesource.com/c/go/+/403814 TryBot-Result: Gopher Robot <gobot@golang.org> Run-TryBot: Kale B <kale@lemnisys.com> Run-TryBot: Ian Lance Taylor <iant@google.com> Reviewed-by: Ian Lance Taylor <iant@google.com> Auto-Submit: Ian Lance Taylor <iant@google.com> Reviewed-by: David Chase <drchase@google.com>