pixie/tests/fuzz_jpeg.nim
treeform 5e484ad4ab
Resurrect old nim-native jpeg parser and fix most issues (#414)
* Add new jpeg tests.
* Resurrect old jpeg.
* Fix Jpeg grayscale
* Fix 4:1:1 scaling.
* Better chunk scanner.
* Fight progressive.
* Fight restart markers.
* Jpeg can now parse all of the test files.
* Fuzzing and overflow checks
* Make getBits* the only way to read the bits. 
* Make Quantiziation and IDCT happen only in one place.
* Rename jpg folder to jpeg
2022-05-05 09:19:17 -07:00

66 lines
2 KiB
Nim

import pixie/common, pixie/fileformats/jpg, random, strformat
randomize()
var files = @[
"tests/fileformats/jpeg/master/red.jpg",
"tests/fileformats/jpeg/master/green.jpg",
"tests/fileformats/jpeg/master/blue.jpg",
"tests/fileformats/jpeg/master/white.jpg",
"tests/fileformats/jpeg/master/black.jpg",
"tests/fileformats/jpeg/master/8x8.jpg",
"tests/fileformats/jpeg/master/8x8_progressive.jpg",
"tests/fileformats/jpeg/master/16x16.jpg",
"tests/fileformats/jpeg/master/16x16_progressive.jpg",
"tests/fileformats/jpeg/master/quality_01.jpg",
"tests/fileformats/jpeg/master/quality_10.jpg",
"tests/fileformats/jpeg/master/quality_25.jpg",
"tests/fileformats/jpeg/master/quality_50.jpg",
"tests/fileformats/jpeg/master/quality_100.jpg",
"tests/fileformats/jpeg/master/cat_4_4_4.jpg",
"tests/fileformats/jpeg/master/cat_4_4_4.jpg",
"tests/fileformats/jpeg/master/cat_4_2_2.jpg",
"tests/fileformats/jpeg/master/cat_4_2_0.jpg",
"tests/fileformats/jpeg/master/cat_4_1_1.jpg",
"tests/fileformats/jpeg/master/cat_4_4_4_progressive.jpg",
"tests/fileformats/jpeg/master/cat_restart_markers_5.jpg",
"tests/fileformats/jpeg/master/cat_restart_markers_5_progressive.jpg",
"tests/fileformats/jpeg/master/mandrill.jpg",
"tests/fileformats/jpeg/master/exif_overrun.jpg",
"tests/fileformats/jpeg/master/grayscale_test.jpg",
"tests/fileformats/jpeg/master/progressive.jpg",
"tests/fileformats/jpeg/master/testimg.jpg",
"tests/fileformats/jpeg/master/testimgp.jpg",
"tests/fileformats/jpeg/master/testorig.jpg",
"tests/fileformats/jpeg/master/testprog.jpg",
]
for i in 0 ..< 10_000:
let original = readFile(sample(files))
var data = original
let
pos = rand(0 ..< data.len)
value = rand(255).uint8
data[pos] = value.char
echo &"{i} {pos} {value}"
try:
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
except PixieError:
discard