Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Panic runtime error: slice bounds out of range #305

Closed
gabstv opened this issue Feb 4, 2020 · 2 comments
Closed

Panic runtime error: slice bounds out of range #305

gabstv opened this issue Feb 4, 2020 · 2 comments
Labels

Comments

@gabstv
Copy link

gabstv commented Feb 4, 2020

Emitter Server - Docker Image
emitter/server:latest
Digest:sha256:ebd92d6930447120d6746505bb35a434c7c311b26caf53baf31d2d2f5da65baa

2020/02/04 12:42:38 [closing] panic recovered: runtime error: slice bounds out of range [:258] with capacity 3 
 goroutine 1738145 [running]:
runtime/debug.Stack(0xc00067ace8, 0x11387c0, 0xc000039a00)
	/usr/local/go/src/runtime/debug/stack.go:24 +0x9d
github.com/emitter-io/emitter/internal/broker.(*Conn).Close(0xc0026f8600, 0xc002e86b98, 0xc00067af68)
	/go-build/src/github.com/emitter-io/emitter/internal/broker/conn.go:301 +0x243
panic(0x11387c0, 0xc000039a00)
	/usr/local/go/src/runtime/panic.go:679 +0x1b2
github.com/emitter-io/emitter/internal/network/mqtt.readString(...)
	/go-build/src/github.com/emitter-io/emitter/internal/network/mqtt/mqtt.go:857
github.com/emitter-io/emitter/internal/network/mqtt.decodeConnect(0xc003e16804, 0x3, 0x3, 0x3, 0x3)
	/go-build/src/github.com/emitter-io/emitter/internal/network/mqtt/mqtt.go:640 +0x601
github.com/emitter-io/emitter/internal/network/mqtt.DecodePacket(0x13b2e20, 0xc004562fc0, 0x10000, 0x197b680, 0x0, 0x0, 0x197b680)
	/go-build/src/github.com/emitter-io/emitter/internal/network/mqtt/mqtt.go:211 +0x270
github.com/emitter-io/emitter/internal/broker.(*Conn).Process(0xc0026f8600, 0x0, 0x0)
	/go-build/src/github.com/emitter-io/emitter/internal/broker/conn.go:128 +0x1ae
created by github.com/emitter-io/emitter/internal/broker.(*Service).onAcceptConn
	/go-build/src/github.com/emitter-io/emitter/internal/broker/service.go:303 +0x6e

This is probably a minor issue, since the panic is recovered and happens during a connection close.

@kelindar
Copy link
Contributor

Indeed, looks like it received some invalid data. Are you able to consistently reproduce this?

@lzh2nix
Copy link
Contributor

lzh2nix commented Mar 2, 2020

@kelindar when i send an invalid data, just telnet 8080 and send a bad data.

➜  emitter git:(master) ✗ telnet 127.0.0.1 8080
Trying 127.0.0.1...
Connected to localhost.
Escape character is '^]'.
10a00100044d51545404c2000a0028363010a00100044d51545404c2000a00283630
Connection closed by foreign host.

and got above like panic

2020/03/02 22:09:27 [closing] panic recovered: runtime error: slice bounds out of range
 goroutine 80 [running]:
runtime/debug.Stack(0xc0003aad38, 0x49e8be0, 0x5374e90)
	/usr/local/go/src/runtime/debug/stack.go:24 +0x9d
github.com/emitter-io/emitter/internal/broker.(*Conn).Close(0xc0002b6880, 0x0, 0x0)
	/Users/lizhengqian/gopath/gocode/src/github.com/emitter-io/emitter/internal/broker/conn.go:301 +0x243
panic(0x49e8be0, 0x5374e90)
	/usr/local/go/src/runtime/panic.go:522 +0x1b5
github.com/emitter-io/emitter/internal/network/mqtt.readString(...)
	/Users/lizhengqian/gopath/gocode/src/github.com/emitter-io/emitter/internal/network/mqtt/mqtt.go:857
github.com/emitter-io/emitter/internal/network/mqtt.decodePublish(0xc0000407e0, 0x30, 0x30, 0x100, 0x30, 0x30)
	/Users/lizhengqian/gopath/gocode/src/github.com/emitter-io/emitter/internal/network/mqtt/mqtt.go:687 +0x202
github.com/emitter-io/emitter/internal/network/mqtt.DecodePacket(0x4d24e40, 0xc0000c3560, 0x10000, 0x5389560, 0x0, 0x0, 0x5389560)
	/Users/lizhengqian/gopath/gocode/src/github.com/emitter-io/emitter/internal/network/mqtt/mqtt.go:215 +0x3eb
github.com/emitter-io/emitter/internal/broker.(*Conn).Process(0xc0002b6880, 0x0, 0x0)
	/Users/lizhengqian/gopath/gocode/src/github.com/emitter-io/emitter/internal/broker/conn.go:128 +0x19a
created by github.com/emitter-io/emitter/internal/broker.(*Service).onAcceptConn
	/Users/lizhengqian/gopath/gocode/src/github.com/emitter-io/emitter/internal/broker/service.go:303 +0x6e

it seemed we should give rdr as parameter to decodexxx, then using rdr.Read() to get data, any good advice?

@kelindar kelindar added the bug label Mar 3, 2020
lzh2nix added a commit to lzh2nix/emitter that referenced this issue Mar 5, 2020
Florimond pushed a commit that referenced this issue Sep 7, 2023
* use slice index instead of copy of 2 value in range

* fix #305
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants