Skip to content

runtime: infinite loop causing stack overflow in bufio #38481

Closed
@Nemo-G

Description

@Nemo-G

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

$ go version
go version go1.13.5 linux/amd64

Does this issue reproduce with the latest release?

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

go env Output
$ go env
GO111MODULE=""
GOARCH="amd64"
GOBIN=""
GOCACHE="/root/.cache/go-build"
GOENV="/root/.config/go/env"
GOEXE=""
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="linux"
GONOPROXY=""
GONOSUMDB=""
GOOS="linux"
GOPATH="/builds/assetstore/asv2/.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"
GCCGO="gccgo"
AR="ar"
CC="gcc"
CXX="g++"
CGO_ENABLED="1"
GOMOD=""
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 -fmessage-length=0 -fdebug-prefix-map=/tmp/go-build762445655=/tmp/go-build -gno-record-gcc-switches"

What did you do?

simply call Write([]byte)

func (b *simpleWriter) writeLine(p []byte) {
	if b.isColored {
		b.wr.Write(p)
		return
	}

	escaped := false
	for i := 0; i < len(p); i++ {
		if !escaped {
			if p[i] == 0x1b && i+1 < len(p) && p[i+1] == '[' {
				escaped = true
			} else {
				err := b.wr.WriteByte(p[i])
				if err != nil {
					fmt.Fprintf(os.Stderr, "[writer] Failed to write to log, %v\n", err)
					b.wr.Reset(b.wr)
					break
				}
			}
		} else {
			if p[i] == 'm' {
				escaped = false
			}
		}
	}
}

What did you expect to see?

We could panic instead.

What did you see instead?

Infinite loop causing stack overflow

runtime: goroutine stack exceeds 1000000000-byte limit
fatal error: stack overflow

runtime stack:
runtime.throw(0x13f9843, 0xe)
    /usr/local/go/src/runtime/panic.go:774 +0x72
runtime.newstack()
    /usr/local/go/src/runtime/stack.go:1046 +0x6e9
runtime.morestack()
    /usr/local/go/src/runtime/asm_amd64.s:449 +0x8f

goroutine 10 [running]:
bufio.(*Writer).Write(0xc000078d40, 0xc0004a0000, 0x10000, 0x10000, 0x0, 0x0, 0x0)
    /usr/local/go/src/bufio/bufio.go:619 +0x246 fp=0xc025ad4320 sp=0xc025ad4318 pc=0x5c1626
bufio.(*Writer).Flush(0xc000078d40, 0x0, 0x0)
    /usr/local/go/src/bufio/bufio.go:593 +0x75 fp=0xc025ad4380 sp=0xc025ad4320 pc=0x5c1255
bufio.(*Writer).Write(0xc000078d40, 0xc0004a0000, 0x10000, 0x10000, 0x0, 0x0, 0x0)
    /usr/local/go/src/bufio/bufio.go:629 +0xe4 fp=0xc025ad43e0 sp=0xc025ad4380 pc=0x5c14c4
bufio.(*Writer).Flush(0xc000078d40, 0x0, 0x0)
    /usr/local/go/src/bufio/bufio.go:593 +0x75 fp=0xc025ad4440 sp=0xc025ad43e0 pc=0x5c1255
bufio.(*Writer).Write(0xc000078d40, 0xc0004a0000, 0x10000, 0x10000, 0x0, 0x0, 0x0)
    /usr/local/go/src/bufio/bufio.go:629 +0xe4 fp=0xc025ad44a0 sp=0xc025ad4440 pc=0x5c14c4
bufio.(*Writer).Flush(0xc000078d40, 0x0, 0x0)
    /usr/local/go/src/bufio/bufio.go:593 +0x75 fp=0xc025ad4500 sp=0xc025ad44a0 pc=0x5c1255
bufio.(*Writer).Write(0xc000078d40, 0xc0004a0000, 0x10000, 0x10000, 0x0, 0x0, 0x0)
    /usr/local/go/src/bufio/bufio.go:629 +0xe4 fp=0xc025ad4560 sp=0xc025ad4500 pc=0x5c14c4
bufio.(*Writer).Flush(0xc000078d40, 0x0, 0x0)
...

Metadata

Metadata

Assignees

No one assigned

    Labels

    FrozenDueToAgeWaitingForInfoIssue is not actionable because of missing required information, which needs to be provided.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions