Skip to content

math/big: panic slice bounds out of range in Rat.GobDecode #56156

@AdamKorcz

Description

@AdamKorcz

Found by OSS-Fuzz: https://bugs.chromium.org/p/oss-fuzz/issues/detail?id=52322

What version of Go are you using (go version)?

1.19.1 and 1.19.2

Does this issue reproduce with the latest release?

Yes

What operating system and processor architecture are you using (go env)?

GO111MODULE=""
GOARCH="amd64"
GOBIN=""
GOCACHE="/home/adam/.cache/go-build"
GOENV="/home/adam/.config/go/env"
GOEXE=""
GOEXPERIMENT=""
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="linux"
GOINSECURE=""
GOMODCACHE="/home/adam/go/pkg/mod"
GONOPROXY=""
GONOSUMDB=""
GOOS="linux"
GOPATH="/home/adam/go"
GOPRIVATE=""
GOPROXY="https://proxy.golang.org,direct"
GOROOT="/usr/local/go"
GOSUMDB="sum.golang.org"
GOTMPDIR=""
GOTOOLDIR="/usr/local/go/pkg/tool/linux_amd64"
GOVCS=""
GOVERSION="go1.19.1"
GCCGO="gccgo"
GOAMD64="v1"
AR="ar"
CC="gcc"
CXX="g++"
CGO_ENABLED="1"
GOMOD="/tmp/forked-istio/go.mod"
GOWORK=""
CGO_CFLAGS="-g -O2"
CGO_CPPFLAGS=""
CGO_CXXFLAGS="-g -O2"
CGO_FFLAGS="-g -O2"
CGO_LDFLAGS="-g -O2"
PKG_CONFIG="pkg-config"
GOGCCFLAGS="-fPIC -m64 -pthread -Wl,--no-gc-sections -fmessage-length=0 -fdebug-prefix-map=/tmp/go-build3333636918=/tmp/go-build -gno-record-gcc-switches"

What did you do?

This program:

package main

import (
        "math/big"
)

func main() {
        i1 := 255
        i2 := 255
        r := big.NewRat(int64(i1), int64(i2))
        buf := []byte{2, 255, 255, 255, 255}
        r.GobDecode(buf)
}

... panics with this stacktrace:

panic: runtime error: slice bounds out of range [5:4]

goroutine 1 [running]:
math/big.(*Rat).GobDecode(0xc00009af30?, {0xc00009af2b?, 0xff?, 0x0?})
        /tmp/go/src/math/big/ratmarsh.go:61 +0x250
main.main()
        /tmp/go-poc/main.go:12 +0x6a
exit status 2

What did you expect to see?

No Panic

What did you see instead?

See stacktrace above.

Metadata

Metadata

Assignees

No one assigned

    Labels

    FrozenDueToAgeNeedsFixThe path to resolution is known, but the work has not been done.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions