Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Thrift memory explosion fix
22c23
---
> "bytes"
475c477,478
---
> const readLimit = 32768
>
482c486
---
> /* Original version
491c495,523
< }
---
> */
> var (
> buf bytes.Buffer
> e error
> b []byte
> )
>
> switch {
> case int(size) <= len(p.buffer):
> b = p.buffer[:size] // avoids allocation for small reads
> case int(size) < readLimit:
> b = make([]byte, size)
> default:
> b = make([]byte, readLimit)
> }
>
> for size > 0 {
> _, e = io.ReadFull(p.trans, b)
> buf.Write(b)
> if e != nil {
> break
> }
> size -= readLimit
> if size < readLimit && size > 0 {
> b = b[:size]
> }
> }
> return buf.String(), NewTProtocolException(e)
> }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment