Skip to content
New issue

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

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

Already on GitHub? # to your account

[BUG] fix: len(buf) => cap(buf) #973

Open
1 task done
BaiZe1998 opened this issue Jan 17, 2025 · 0 comments
Open
1 task done

[BUG] fix: len(buf) => cap(buf) #973

BaiZe1998 opened this issue Jan 17, 2025 · 0 comments
Labels

Comments

@BaiZe1998
Copy link

BaiZe1998 commented Jan 17, 2025

Is there an existing issue for this?

  • I have searched the existing issues

Current Behavior

Description

len(buf) must equal to 0 for AvailableBuffer()

// AvailableBuffer returns an empty buffer with b.Available() capacity.
// This buffer is intended to be appended to and
// passed to an immediately succeeding [Writer.Write] call.
// The buffer is only valid until the next write operation on b.
func (b *Writer) AvailableBuffer() []byte {
	return b.buf[b.n:][:0]
}

i think the len(buf) may switch to cap(buf) ?

https://github.com/gorilla/websocket/blob/main/server.go#L208

buf := brw.Writer.AvailableBuffer()

var writeBuf []byte
if u.WriteBufferPool == nil && u.WriteBufferSize == 0 && len(buf) >= maxFrameHeaderSize+256 {
    // Reuse hijacked write buffer as connection buffer.
    writeBuf = buf
}

i commit a fix pr: #972

Expected Behavior

No response

Steps To Reproduce

No response

Anything else?

No response

@BaiZe1998 BaiZe1998 added the bug label Jan 17, 2025
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant