From 287d9bc80e1afdfd48a451864ec4ff5dd3955a1c Mon Sep 17 00:00:00 2001 From: Ryan Oldenburg Date: Mon, 29 May 2023 00:10:23 -0500 Subject: [PATCH] fix bounds check --- src/pixie/fileformats/ppm.nim | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/src/pixie/fileformats/ppm.nim b/src/pixie/fileformats/ppm.nim index c81e6f7..4bba3d4 100644 --- a/src/pixie/fileformats/ppm.nim +++ b/src/pixie/fileformats/ppm.nim @@ -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