pixie/tests/fuzz_jpeg.nim
Ryan Oldenburg 35efcf1495 jpeg version
2022-05-12 18:47:53 -05:00

25 lines
560 B
Nim

import jpegsuite, pixie/common, pixie/fileformats/jpeg, random, strformat
randomize()
for i in 0 ..< 10_000:
let file = sample(jpegSuiteFiles)
var data = readFile(file)
let
pos = rand(0 ..< data.len)
value = rand(255).uint8
data[pos] = value.char
echo &"{i} {file} {pos} {value}"
try:
let img = decodeJpeg(data)
doAssert img.height > 0 and img.width > 0
except PixieError:
discard
data = data[0 ..< pos]
try:
let img = decodeJpeg(data)
doAssert img.height > 0 and img.width > 0
except PixieError:
discard