Skip to content

Commit

Permalink
Merge pull request #44247 from thaJeztah/20.10_bump_go_1.18.7
Browse files Browse the repository at this point in the history
[20.10] Update to go 1.18.7 to address CVE-2022-2879, CVE-2022-2880, CVE-2022-41715
  • Loading branch information
thaJeztah committed Oct 6, 2022
2 parents 35eaf7e + 11bdbf4 commit 435c40c
Show file tree
Hide file tree
Showing 10 changed files with 60 additions and 7 deletions.
2 changes: 1 addition & 1 deletion Dockerfile
Expand Up @@ -3,7 +3,7 @@
ARG CROSS="false"
ARG SYSTEMD="false"
# IMPORTANT: When updating this please note that stdlib archive/tar pkg is vendored
ARG GO_VERSION=1.18.6
ARG GO_VERSION=1.18.7
ARG DEBIAN_FRONTEND=noninteractive
ARG VPNKIT_VERSION=0.5.0
ARG DOCKER_BUILDTAGS="apparmor seccomp"
Expand Down
2 changes: 1 addition & 1 deletion Dockerfile.e2e
@@ -1,4 +1,4 @@
ARG GO_VERSION=1.18.6
ARG GO_VERSION=1.18.7

FROM golang:${GO_VERSION}-alpine AS base
ENV GO111MODULE=off
Expand Down
2 changes: 1 addition & 1 deletion Dockerfile.simple
Expand Up @@ -5,7 +5,7 @@

# This represents the bare minimum required to build and test Docker.

ARG GO_VERSION=1.18.6
ARG GO_VERSION=1.18.7

FROM golang:${GO_VERSION}-buster
ENV GO111MODULE=off
Expand Down
2 changes: 1 addition & 1 deletion Dockerfile.windows
Expand Up @@ -165,7 +165,7 @@ FROM microsoft/windowsservercore
# Use PowerShell as the default shell
SHELL ["powershell", "-Command", "$ErrorActionPreference = 'Stop'; $ProgressPreference = 'SilentlyContinue';"]

ARG GO_VERSION=1.18.6
ARG GO_VERSION=1.18.7
ARG GOTESTSUM_VERSION=v1.7.0

# Environment variable notes:
Expand Down
4 changes: 4 additions & 0 deletions vendor/archive/tar/format.go
Expand Up @@ -143,6 +143,10 @@ const (
blockSize = 512 // Size of each block in a tar stream
nameSize = 100 // Max length of the name field in USTAR format
prefixSize = 155 // Max length of the prefix field in USTAR format

// Max length of a special file (PAX header, GNU long name or link).
// This matches the limit used by libarchive.
maxSpecialFileSize = 1 << 20
)

// blockPadding computes the number of bytes needed to pad offset up to the
Expand Down
14 changes: 12 additions & 2 deletions vendor/archive/tar/reader.go
Expand Up @@ -103,7 +103,7 @@ func (tr *Reader) next() (*Header, error) {
continue // This is a meta header affecting the next header
case TypeGNULongName, TypeGNULongLink:
format.mayOnlyBe(FormatGNU)
realname, err := io.ReadAll(tr)
realname, err := readSpecialFile(tr)
if err != nil {
return nil, err
}
Expand Down Expand Up @@ -293,7 +293,7 @@ func mergePAX(hdr *Header, paxHdrs map[string]string) (err error) {
// parsePAX parses PAX headers.
// If an extended header (type 'x') is invalid, ErrHeader is returned
func parsePAX(r io.Reader) (map[string]string, error) {
buf, err := io.ReadAll(r)
buf, err := readSpecialFile(r)
if err != nil {
return nil, err
}
Expand Down Expand Up @@ -828,6 +828,16 @@ func tryReadFull(r io.Reader, b []byte) (n int, err error) {
return n, err
}

// readSpecialFile is like io.ReadAll except it returns
// ErrFieldTooLong if more than maxSpecialFileSize is read.
func readSpecialFile(r io.Reader) ([]byte, error) {
buf, err := io.ReadAll(io.LimitReader(r, maxSpecialFileSize+1))
if len(buf) > maxSpecialFileSize {
return nil, ErrFieldTooLong
}
return buf, err
}

// discard skips n bytes in r, reporting an error if unable to do so.
func discard(r io.Reader, n int64) error {
// If possible, Seek to the last byte before the end of the data section.
Expand Down
11 changes: 10 additions & 1 deletion vendor/archive/tar/reader_test.go
Expand Up @@ -6,6 +6,7 @@ package tar

import (
"bytes"
"compress/bzip2"
"crypto/md5"
"errors"
"fmt"
Expand Down Expand Up @@ -243,6 +244,9 @@ func TestReader(t *testing.T) {
}, {
file: "testdata/pax-bad-hdr-file.tar",
err: ErrHeader,
}, {
file: "testdata/pax-bad-hdr-large.tar.bz2",
err: ErrFieldTooLong,
}, {
file: "testdata/pax-bad-mtime-file.tar",
err: ErrHeader,
Expand Down Expand Up @@ -625,9 +629,14 @@ func TestReader(t *testing.T) {
}
defer f.Close()

var fr io.Reader = f
if strings.HasSuffix(v.file, ".bz2") {
fr = bzip2.NewReader(fr)
}

// Capture all headers and checksums.
var (
tr = NewReader(f)
tr = NewReader(fr)
hdrs []*Header
chksums []string
rdbuf = make([]byte, 8)
Expand Down
Binary file not shown.
3 changes: 3 additions & 0 deletions vendor/archive/tar/writer.go
Expand Up @@ -199,6 +199,9 @@ func (tw *Writer) writePAXHeader(hdr *Header, paxHdrs map[string]string) error {
flag = TypeXHeader
}
data := buf.String()
if len(data) > maxSpecialFileSize {
return ErrFieldTooLong
}
if err := tw.writeRawFile(name, data, flag, FormatPAX); err != nil || isGlobal {
return err // Global headers return here
}
Expand Down
27 changes: 27 additions & 0 deletions vendor/archive/tar/writer_test.go
Expand Up @@ -1004,6 +1004,33 @@ func TestIssue12594(t *testing.T) {
}
}

func TestWriteLongHeader(t *testing.T) {
for _, test := range []struct {
name string
h *Header
}{{
name: "name too long",
h: &Header{Name: strings.Repeat("a", maxSpecialFileSize)},
}, {
name: "linkname too long",
h: &Header{Linkname: strings.Repeat("a", maxSpecialFileSize)},
}, {
name: "uname too long",
h: &Header{Uname: strings.Repeat("a", maxSpecialFileSize)},
}, {
name: "gname too long",
h: &Header{Gname: strings.Repeat("a", maxSpecialFileSize)},
}, {
name: "PAX header too long",
h: &Header{PAXRecords: map[string]string{"GOLANG.x": strings.Repeat("a", maxSpecialFileSize)}},
}} {
w := NewWriter(io.Discard)
if err := w.WriteHeader(test.h); err != ErrFieldTooLong {
t.Errorf("%v: w.WriteHeader() = %v, want ErrFieldTooLong", test.name, err)
}
}
}

// testNonEmptyWriter wraps an io.Writer and ensures that
// Write is never called with an empty buffer.
type testNonEmptyWriter struct{ io.Writer }
Expand Down

0 comments on commit 435c40c

Please sign in to comment.