Add defensive check for one stream message size (#15029)

In a streaming response, the client knows the size of a streamed
message but never checks the message size. Add the check to error 
out if the response message is truncated.
This commit is contained in:
Anis Elleuch 2022-06-02 17:16:26 +01:00 committed by GitHub
parent 1fce2b180f
commit d4e565e595
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -1067,10 +1067,13 @@ func waitForHTTPStream(respBody io.ReadCloser, w io.Writer) error {
return err
}
length := binary.LittleEndian.Uint32(tmp[:])
_, err = io.CopyBuffer(w, io.LimitReader(respBody, int64(length)), buf)
n, err := io.CopyBuffer(w, io.LimitReader(respBody, int64(length)), buf)
if err != nil {
return err
}
if n != int64(length) {
return io.ErrUnexpectedEOF
}
continue
case 32:
continue