chore: Add early bounds checks

This commit is contained in:
H1JK 2023-04-05 13:51:50 +08:00
parent ee5c4cb83b
commit ae722bb1a0
2 changed files with 2 additions and 0 deletions

View file

@ -147,6 +147,7 @@ func (g *Conn) WriteBuffer(buffer *buf.Buffer) error {
dataLen := buffer.Len()
varLen := UVarintLen(uint64(dataLen))
header := buffer.ExtendHeader(6 + varLen)
_ = header[6] // bounds check hint to compiler
header[0] = 0x00
binary.BigEndian.PutUint32(header[1:5], uint32(1+varLen+dataLen))
header[5] = 0x0A

View file

@ -107,6 +107,7 @@ func (wsc *websocketConn) WriteBuffer(buffer *buf.Buffer) error {
headerLen += 4 // MASK KEY
header := buffer.ExtendHeader(headerLen)
_ = header[2] // bounds check hint to compiler
header[0] = websocket.BinaryMessage | 1<<7
header[1] = 1 << 7