pixie/tests/fuzz_jpg.nim

26 lines
570 B
Nim
Raw Normal View History

2021-02-14 18:27:32 +00:00
import pixie/common, pixie/fileformats/jpg, random, strformat
2020-11-29 21:52:53 +00:00
randomize()
2021-10-03 22:49:21 +00:00
let original = cast[seq[uint8]](readFile("tests/fileformats/jpg/jpeg420exif.jpg"))
2020-11-29 21:52:53 +00:00
for i in 0 ..< 10_000:
var data = original
let
pos = rand(data.len)
value = rand(255).uint8
data[pos] = value
echo &"{i} {pos} {value}"
try:
2021-01-03 17:18:15 +00:00
let img = decodeJpg(data)
doAssert img.height > 0 and img.width > 0
except PixieError:
discard
data = data[0 ..< pos]
try:
let img = decodeJpg(data)
doAssert img.height > 0 and img.width > 0
2020-11-29 21:52:53 +00:00
except PixieError:
discard