[go] archive/tar: check for non-ASCII bytes without decoding runes

0 views
Skip to first unread message

Gopher Robot (Gerrit)

unread,
Aug 10, 2026, 12:44:47 PM (17 hours ago) Aug 10
to David Teather, Gerrit Bot, goph...@pubsubhelper.golang.org, golang-...@googlegroups.com, Dmitri Shuralyov, Dmitri Shuralyov, Mark Freeman, golang...@luci-project-accounts.iam.gserviceaccount.com, qiu laidongfeng, Joseph Tsai, golang-co...@googlegroups.com

Gopher Robot submitted the change

Change information

Commit message:
archive/tar: check for non-ASCII bytes without decoding runes

readHeader used bytes.IndexFunc with a rune predicate to reject USTAR
and PAX headers containing non-ASCII bytes, making an uninlinable
indirect call for every byte of the 512-byte block. Scanning the
bytes directly rejects exactly the same blocks: ASCII bytes decode
one at a time, so the old scan always reached the first byte >= 0x80,
where DecodeRune returns a rune >= 0x80 (possibly RuneError).

goos: darwin
goarch: arm64
pkg: archive/tar
cpu: Apple M2 Pro
│ old │ new │
│ sec/op │ sec/op vs base │
/Reader/USTAR-10 1.955µ ± 1% 1.098µ ± 1% -43.84% (p=0.000 n=25)
/Reader/GNU-10 909.5n ± 1% 904.9n ± 1% ~ (p=0.211 n=25)
/Reader/PAX-10 4.331µ ± 1% 2.569µ ± 1% -40.68% (p=0.000 n=25)
geomean 1.975µ 1.367µ -30.79%

Fixes #80633
Change-Id: I47dd7490e06d2096fad1fa90b0fc9cabaaeb3cc3
GitHub-Last-Rev: 05dd37d6007e85fec8d489ff4df25271b5eb7005
GitHub-Pull-Request: golang/go#80634
Auto-Submit: Sean Liao <se...@liao.dev>
Reviewed-by: Mark Freeman <markf...@google.com>
Reviewed-by: Dmitri Shuralyov <dmit...@google.com>
Reviewed-by: Sean Liao <se...@liao.dev>
Files:
  • M src/archive/tar/reader.go
Change size: XS
Delta: 1 file changed, 5 insertions(+), 3 deletions(-)
Branch: refs/heads/master
Submit Requirements:
Open in Gerrit
Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. DiffyGerrit
Gerrit-MessageType: merged
Gerrit-Project: go
Gerrit-Branch: master
Gerrit-Change-Id: I47dd7490e06d2096fad1fa90b0fc9cabaaeb3cc3
Gerrit-Change-Number: 807800
Gerrit-PatchSet: 3
Gerrit-Owner: Gerrit Bot <letsus...@gmail.com>
Gerrit-Reviewer: Dmitri Shuralyov <dmit...@google.com>
Gerrit-Reviewer: Gopher Robot <go...@golang.org>
Gerrit-Reviewer: Joseph Tsai <joe...@digital-static.net>
Gerrit-Reviewer: Mark Freeman <markf...@google.com>
Gerrit-Reviewer: Sean Liao <se...@liao.dev>
Gerrit-Reviewer: qiu laidongfeng <26454...@qq.com>
Gerrit-CC: David Teather <contact.da...@gmail.com>
Gerrit-CC: Dmitri Shuralyov <dmit...@golang.org>
open
diffy
satisfied_requirement
Reply all
Reply to author
Forward
0 new messages