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

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

Open
CGongsz opened this issue Aug 6, 2024 · 1 comment
Open

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

CGongsz opened this issue Aug 6, 2024 · 1 comment
Labels
bug Something isn't working

Comments

@CGongsz
Copy link

CGongsz commented Aug 6, 2024

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 CGongsz added the bug Something isn't working label Aug 6, 2024
@CGongsz
Copy link
Author

CGongsz commented Aug 9, 2024

The fields in the response body are all default values, 'buf' will always be an empty slice

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant