gopkg icon indicating copy to clipboard operation
gopkg copied to clipboard

mcache.Free(data) panic, when the data is an empty slice

Open CGongsz opened this issue 6 months ago • 1 comments

Operating System

macos

Go Version

go 1.22.1

Package Version

all version

Affected Packages

protobuf/grpc_compress.go

Expected Behavior

returned normally

Actual Behavior

panic index out of range [-1]

Reproduction Steps

1、Define the empty reponse
message XXXRes { } 2、Write an arbitrary compressor and register it (encoding.RegisterCompressor(compressor)) 3、Triggering the request 4、When the request returns,have a panic,'index out of range [-1]'

Other Information

mcache.Free

func Free(buf []byte) { size := cap(buf) if !isPowerOfTwo(size) { return } buf = buf[:0] caches[bsr(size)].Put(buf) } when size = 0,bsr(size) return -1

caches[-1] = nil

CGongsz avatar Aug 06 '24 10:08 CGongsz