Thanks to visit codestin.com
Credit goes to github.com

Skip to content

x/net/html: panic: runtime error: index out of range #27846

@tr3ee

Description

@tr3ee

Please answer these questions before submitting your issue. Thanks!

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

go version go1.10.3 windows/amd64

Does this issue reproduce with the latest release?

yes

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

set GOARCH=amd64
set GOBIN=
set GOEXE=.exe
set GOHOSTARCH=amd64
set GOHOSTOS=windows
set GOOS=windows
set GORACE=
set GOTMPDIR=
set GCCGO=gccgo
set CC=gcc
set CXX=g++
set CGO_ENABLED=1
set CGO_CFLAGS=-g -O2
set CGO_CPPFLAGS=
set CGO_CXXFLAGS=-g -O2
set CGO_FFLAGS=-g -O2
set CGO_LDFLAGS=-g -O2
set PKG_CONFIG=pkg-config

NOTE: there are two different issues below

BUG 1

What did you do?

package main

import (
	"strings"

	"golang.org/x/net/html"
)

func main() {
	r := strings.NewReader("<svg><template><desc><t><svg></template>")
	html.Parse(r)
}

What did you expect to see?

No panic exit

What did you see instead?

panic: runtime error: index out of range

goroutine 1 [running]:
golang.org/x/net/html.(*nodeStack).pop(...)
        /path/to/gopath/src/golang.org/x/net/html/node.go:153
golang.org/x/net/html.(*parser).clearActiveFormattingElements(0xc042050410)
        /path/to/gopath/src/golang.org/x/net/html/parse.go:372 +0x4d
golang.org/x/net/html.inHeadIM(0xc042050410, 0x40df23)
        /path/to/gopath/src/golang.org/x/net/html/parse.go:675 +0xff
golang.org/x/net/html.inBodyIM(0xc042050410, 0x2)
        /path/to/gopath/src/golang.org/x/net/html/parse.go:1138 +0x3425
golang.org/x/net/html.parseForeignContent(0xc042050410, 0x1)
        /path/to/gopath/src/golang.org/x/net/html/parse.go:2122 +0x80a
golang.org/x/net/html.(*parser).parseCurrentToken(0xc042050410)
        /path/to/gopath/src/golang.org/x/net/html/parse.go:2190 +0x6f
golang.org/x/net/html.(*parser).parse(0xc042050410, 0xc0420a2000, 0xc042050340)
        /path/to/gopath/src/golang.org/x/net/html/parse.go:2218 +0x62
golang.org/x/net/html.Parse(0x4e14c0, 0xc0420024c0, 0xc0420661e0, 0xc04206ff78, 0xc042048058)
        /path/to/gopath/src/golang.org/x/net/html/parse.go:2244 +0xe2
main.main()
        /path/to/gopath/src/main.go:11 +0x7a
exit status 2

BUG 2

What did you do?

package main

import (
	"strings"

	"golang.org/x/net/html"
)

func main() {
	r := strings.NewReader("<math><template><mn><b></template>")
	html.Parse(r)
}

What did you expect to see?

No panic exit

What did you see instead?

panic: runtime error: index out of range

goroutine 1 [running]:
golang.org/x/net/html.(*insertionModeStack).pop(...)
        /path/to/gopath/src/golang.org/x/net/html/node.go:210
golang.org/x/net/html.inHeadIM(0xc042056340, 0x40)
        /path/to/gopath/src/golang.org/x/net/html/parse.go:676 +0x74f
golang.org/x/net/html.inBodyIM(0xc042056340, 0x0)
        /path/to/gopath/src/golang.org/x/net/html/parse.go:1138 +0x3425
golang.org/x/net/html.(*parser).parseCurrentToken(0xc042056340)
        /path/to/gopath/src/golang.org/x/net/html/parse.go:2192 +0x8b
golang.org/x/net/html.(*parser).parse(0xc042056340, 0xc0420b6000, 0xc042056270)
        /path/to/gopath/src/golang.org/x/net/html/parse.go:2218 +0x62
golang.org/x/net/html.Parse(0x4e14c0, 0xc042054460, 0xc0420701e0, 0xc042079f78, 0xc042048058)
        /path/to/gopath/src/golang.org/x/net/html/parse.go:2244 +0xe2
main.main()
        /path/to/gopath/src/main.go:11 +0x7a
exit status 2

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions