Last active
April 28, 2016 21:22
-
-
Save kaedys/53b8fd05690d5d8f202afa7878d6e3d5 to your computer and use it in GitHub Desktop.
Thrift memory explosion fix
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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