pixie/tests/fuzz_png.nim

27 lines
636 B
Nim
Raw Normal View History

2020-11-21 02:21:27 +00:00
import random, strformat, pixie/fileformats/png, pixie/common, pngsuite
randomize()
for i in 0 ..< 10_000:
let file = pngSuiteFiles[rand(pngSuiteFiles.len - 1)]
2020-11-28 04:51:08 +00:00
var data = cast[seq[uint8]](
readFile(&"tests/images/png/pngsuite/{file}.png")
)
2020-11-21 02:21:27 +00:00
let
pos = 29 + rand(data.len - 30)
value = rand(255).uint8
data[pos] = value
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