pixie/tests/fuzz_png.nim

25 lines
620 B
Nim
Raw Normal View History

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