]> Cypherpunks.ru repositories - gostls13.git/commit
encoding/binary: limit bytes read by Uvarint to <= 10
authorEmmanuel T Odeke <emmanuel@orijtech.com>
Sun, 7 Mar 2021 07:14:21 +0000 (23:14 -0800)
committerEmmanuel Odeke <emmanuel@orijtech.com>
Mon, 8 Mar 2021 18:49:14 +0000 (18:49 +0000)
commitaafad20b617ee63d58fcd4f6e0d98fe27760678c
tree6359968324c31731f8bcf2376759ba48211b3307
parent125eca0f7210da1bbf1a4a1460a87d1c33366b99
encoding/binary: limit bytes read by Uvarint to <= 10

Limits the number of bytes that can be consumed by Uvarint
to MaxVarintLen64 (10) to avoid wasted computations.
With this change, if Uvarint reads more than MaxVarintLen64
bytes, it'll return the erroring byte count of n=-(MaxVarintLen64+1)
which is -11, as per the function signature.

Updated some tests to reflect the new change in expectations of n
when the number of bytes to be read exceeds the limits..

Fixes #41185

Change-Id: Ie346457b1ddb0214b60c72e81128e24d604d083d
Reviewed-on: https://go-review.googlesource.com/c/go/+/299531
Run-TryBot: Emmanuel Odeke <emmanuel@orijtech.com>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Keith Randall <khr@golang.org>
Trust: Emmanuel Odeke <emmanuel@orijtech.com>
src/encoding/binary/varint.go
src/encoding/binary/varint_test.go