Improve connection.nim read error clarity when buffer overflow

This commit is contained in:
Giovanni Petrantoni 2020-02-07 15:40:16 +09:00 committed by Dmitriy Ryajov
parent 120ba0d528
commit f9cbdc252f
1 changed files with 3 additions and 1 deletions

View File

@ -122,8 +122,10 @@ proc readLp*(s: Connection): Future[seq[byte]] {.async, gcsafe.} =
res = LP.getUVarint(buff.toOpenArray(0, i), length, size)
if res == VarintStatus.Success:
break
if res != VarintStatus.Success or size > DefaultReadSize:
if res != VarintStatus.Success:
raise newInvalidVarintException()
if size > DefaultReadSize:
raise newLPStreamLimitError()
buff.setLen(size)
if size > 0.uint:
trace "reading exact bytes from stream", size = size