Allow bounding the maximum decoded size

This commit is contained in:
Zahary Karadjov 2020-08-18 17:34:55 +03:00
parent cae6c07fbb
commit f449a5a47a
No known key found for this signature in database
GPG Key ID: C8936F8A3073D609
1 changed files with 2 additions and 2 deletions

View File

@ -453,9 +453,9 @@ func encode*(src: openarray[byte]): seq[byte] =
# decodedLen returns the length of the decoded block and the number of bytes
# that the length header occupied.
func decode*(src: openArray[byte]): seq[byte] =
func decode*(src: openArray[byte], maxSize = 0xffffffff'u64): seq[byte] =
let (len, bytesRead) = uvarint(src)
if bytesRead <= 0 or len > 0xffffffff'u64:
if bytesRead <= 0 or len > maxSize:
return
const wordSize = sizeof(uint) * 8