Skip to content
This repository was archived by the owner on Oct 13, 2023. It is now read-only.

Commit 0742850

Browse files
tonistiigiTibor Vass
authored andcommitted
vendor: add local copy of archive/tar
This version avoids doing name lookups on creating tarball that should be avoided in to not hit loading glibc shared libraries. Signed-off-by: Tonis Tiigi <tonistiigi@gmail.com> Upstream-commit: aa6a9891b09cce3d9004121294301a30d45d998d Component: engine
1 parent 618fcb5 commit 0742850

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

62 files changed

+7354
-2
lines changed

components/engine/Dockerfile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
#
2626

2727
ARG CROSS="false"
28+
# IMPORTANT: When updating this please note that stdlib archive/tar pkg is vendored
2829
ARG GO_VERSION=1.12.17
2930
ARG DEBIAN_FRONTEND=noninteractive
3031

components/engine/hack/validate/vendor

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ validate_vendor_diff(){
1010

1111
if [ ${#files[@]} -gt 0 ]; then
1212
# recreate vendor/
13-
vndr
13+
vndr -whitelist=^archive/tar
1414
# check if any files have changed
1515
diffs="$(git status --porcelain -- vendor 2>/dev/null)"
1616
if [ "$diffs" ]; then

components/engine/hack/vendor.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,4 +12,4 @@ if ! hash vndr; then
1212
exit 1
1313
fi
1414

15-
vndr "$@"
15+
vndr -whitelist=^archive/tar "$@"
Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
From bc0de86b495ae014b209431ed7cb90fc3d5e4d1f Mon Sep 17 00:00:00 2001
2+
From: Kir Kolyshkin <kolyshkin@gmail.com>
3+
Date: Mon, 9 Apr 2018 15:58:40 -0700
4+
Subject: [PATCH] archive/tar: do not populate user/group names
5+
6+
This reverts part of commit 29a18899379c ("archive/tar: populate
7+
uname/gname/devmajor/devminor in FileInfoHeader"). The reason is
8+
using os/user functions to resolved uids/gids to names breaks
9+
the static build for Linux/glibc case (the resulting binary panics
10+
on NULL pointer dereference).
11+
12+
For much more details, see https://github.com/golang/go/issues/23265
13+
14+
This is ultimately fixed in Go 1.11 (provided that "osusergo" build tag
15+
is set (see https://github.com/golang/go/commit/62f0127d81). In the
16+
meantime, let's use this fork.
17+
18+
Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
19+
---
20+
src/archive/tar/stat_unix.go | 26 +++-----------------------
21+
1 file changed, 3 insertions(+), 23 deletions(-)
22+
23+
diff --git a/src/archive/tar/stat_unix.go b/src/archive/tar/stat_unix.go
24+
index 868105f338..9640ed4bab 100644
25+
--- a/src/archive/tar/stat_unix.go
26+
+++ b/src/archive/tar/stat_unix.go
27+
@@ -8,10 +8,7 @@ package tar
28+
29+
import (
30+
"os"
31+
- "os/user"
32+
"runtime"
33+
- "strconv"
34+
- "sync"
35+
"syscall"
36+
)
37+
38+
@@ -19,10 +16,6 @@ func init() {
39+
sysStat = statUnix
40+
}
41+
42+
-// userMap and groupMap caches UID and GID lookups for performance reasons.
43+
-// The downside is that renaming uname or gname by the OS never takes effect.
44+
-var userMap, groupMap sync.Map // map[int]string
45+
-
46+
func statUnix(fi os.FileInfo, h *Header) error {
47+
sys, ok := fi.Sys().(*syscall.Stat_t)
48+
if !ok {
49+
@@ -31,22 +24,9 @@ func statUnix(fi os.FileInfo, h *Header) error {
50+
h.Uid = int(sys.Uid)
51+
h.Gid = int(sys.Gid)
52+
53+
- // Best effort at populating Uname and Gname.
54+
- // The os/user functions may fail for any number of reasons
55+
- // (not implemented on that platform, cgo not enabled, etc).
56+
- if u, ok := userMap.Load(h.Uid); ok {
57+
- h.Uname = u.(string)
58+
- } else if u, err := user.LookupId(strconv.Itoa(h.Uid)); err == nil {
59+
- h.Uname = u.Username
60+
- userMap.Store(h.Uid, h.Uname)
61+
- }
62+
- if g, ok := groupMap.Load(h.Gid); ok {
63+
- h.Gname = g.(string)
64+
- } else if g, err := user.LookupGroupId(strconv.Itoa(h.Gid)); err == nil {
65+
- h.Gname = g.Name
66+
- groupMap.Store(h.Gid, h.Gname)
67+
- }
68+
-
69+
+ // TODO(bradfitz): populate username & group. os/user
70+
+ // doesn't cache LookupId lookups, and lacks group
71+
+ // lookup functions.
72+
h.AccessTime = statAtime(sys)
73+
h.ChangeTime = statCtime(sys)
74+
75+
76+
base-commit: 4af1337d1e9eb9e7b766c9deb787c78413bb25c4
77+
--
78+
2.24.1
79+

components/engine/vendor.conf

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -163,4 +163,13 @@ github.com/docker/go-metrics d466d4f6fd960e01820085bd7e1a
163163

164164
github.com/opencontainers/selinux 4defb1c884d2f4f9c890c615380f20f7fc215cf3 # v1.3.1
165165

166+
167+
# archive/tar
168+
# mkdir -p ./vendor/archive
169+
# git clone -b go1.12.16 --depth=1 git://github.com/golang/go.git ./go
170+
# git --git-dir ./go/.git --work-tree ./go am ../patches/0001-archive-tar-do-not-populate-user-group-names.patch
171+
# cp -a go/src/archive/tar ./vendor/archive/tar
172+
# rm -rf ./go
173+
# vndr
174+
166175
# DO NOT EDIT BELOW THIS LINE -------- reserved for downstream projects --------

0 commit comments

Comments
 (0)