fix bounds check
This commit is contained in:
parent
93ade8c889
commit
287d9bc80e
|
@ -15,14 +15,13 @@ template failInvalid() =
|
||||||
proc decodeHeader(
|
proc decodeHeader(
|
||||||
data: ptr UncheckedArray[uint8], len: int
|
data: ptr UncheckedArray[uint8], len: int
|
||||||
): PpmHeader {.raises: [PixieError].} =
|
): PpmHeader {.raises: [PixieError].} =
|
||||||
if len <= 10: # Each part + whitespace
|
|
||||||
raise newException(PixieError, "Invalid PPM file header")
|
|
||||||
|
|
||||||
var
|
var
|
||||||
commentMode, readWhitespace: bool
|
commentMode, readWhitespace: bool
|
||||||
i, readFields: int
|
i, readFields: int
|
||||||
field: string
|
field: string
|
||||||
while readFields < 4:
|
while readFields < 4:
|
||||||
|
if i >= len:
|
||||||
|
raise newException(PixieError, "Invalid PPM file header")
|
||||||
let c = data[i].char
|
let c = data[i].char
|
||||||
if c == '#':
|
if c == '#':
|
||||||
commentMode = true
|
commentMode = true
|
||||||
|
|
Loading…
Reference in a new issue