Closed shengery closed 6 years ago
Hi @shengery!
Looks like the f.Header.Length
is too big:
// /usr/local/go/src/runtime/slice.go
func makeslice(et *_type, len, cap int) slice {
// NOTE: The len > maxElements check here is not strictly necessary,
// but it produces a 'len out of range' error instead of a 'cap out of range' error
// when someone does make([]T, bignumber). 'cap out of range' is true too,
// but since the cap is only being supplied implicitly, saying len is clearer.
// See issue 4085.
maxElements := maxSliceCap(et.size)
if len < 0 || uintptr(len) > maxElements {
panic(errorString("makeslice: len out of range"))
}
...
}
Looking at ws.ReadHeader
code it is not possible to receive negative frame length.
So, there could be few cases when this happens:
So the solution is to split ws.ReadFrame
into ws.ReadHeader
, check the header, and then ws.ReadFrame
.
Also, take a look at this helper function to preare RFC header checks. But notice that there is no Length
check because it is not limited by RFC.
Do you mean that I handle the frame.Header in my code instead of directly calling ws.ReadFrame?
Yes, ReadFrame()
just makes ReadHeader()
and then make([]byte, header.Length)
.
OK,thanks for your reply, I will call ReadHeader and readbody seperately
Greetings,
We are deploying our chat servers in the production env, the connsrv is the gateway server between clients and internal logic server, which is serving websocket requests , however , we met an unusual panic last day The panic stack is :
The location of the panic in read.go is :
However , we don't know how much the frame.length is..
The
/data/home/user_00/go_workspace/src/aladinfun.com/midware/goim/srv/connsrv/conn_ws.go:49
is below