pixie/tests/fuzz_jpeg.nim

25 lines
560 B
Nim
Raw Normal View History

2022-05-12 23:47:53 +00:00
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:
2022-05-12 23:47:53 +00:00
let img = decodeJpeg(data)
doAssert img.height > 0 and img.width > 0
except PixieError:
discard
data = data[0 ..< pos]
try:
2022-05-12 23:47:53 +00:00
let img = decodeJpeg(data)
doAssert img.height > 0 and img.width > 0
except PixieError:
discard