fix bounds check

This commit is contained in:
Ryan Oldenburg 2023-05-29 00:10:23 -05:00
parent 93ade8c889
commit 287d9bc80e

View file

@ -15,14 +15,13 @@ template failInvalid() =
proc decodeHeader(
data: ptr UncheckedArray[uint8], len: int
): PpmHeader {.raises: [PixieError].} =
if len <= 10: # Each part + whitespace
raise newException(PixieError, "Invalid PPM file header")
var
commentMode, readWhitespace: bool
i, readFields: int
field: string
while readFields < 4:
if i >= len:
raise newException(PixieError, "Invalid PPM file header")
let c = data[i].char
if c == '#':
commentMode = true