corrupted file tests

This commit is contained in:
Ryan Oldenburg 2020-11-21 00:12:55 -06:00
parent 344063ddbc
commit c0803c3336
2 changed files with 99 additions and 72 deletions

View file

@ -1,4 +1,7 @@
const pngSuiteFiles* = [ # http://www.schaik.com/pngsuite/
const
pngSuiteFiles* = [
# Basic # Basic
"basn0g01", # black & white "basn0g01", # black & white
"basn0g02", # 2 bit (4 level) grayscale "basn0g02", # 2 bit (4 level) grayscale
@ -71,3 +74,20 @@ const pngSuiteFiles* = [
# "s40i3p04", # 40x40 paletted file, interlaced # "s40i3p04", # 40x40 paletted file, interlaced
"s40n3p04", # 40x40 paletted file, no interlacing "s40n3p04", # 40x40 paletted file, no interlacing
] ]
pngSuiteCorruptedFiles* = [
"xs1n0g01", # signature byte 1 MSBit reset to zero
"xs2n0g01", # signature byte 2 is a 'Q'
"xs4n0g01", # signature byte 4 lowercase
"xs7n0g01", # 7th byte a space instead of control-Z
"xcrn0g04", # added cr bytes
"xlfn0g04", # added lf bytes
# "xhdn0g08", # incorrect IHDR checksum
"xc1n0g08", # color type 1
"xc9n2c08", # color type 9
"xd0n2c08", # bit-depth 0
"xd3n2c08", # bit-depth 3
"xd9n2c08", # bit-depth 99
"xdtn0g01", # missing IDAT chunk
# "xcsn0g01" # incorrect IDAT checksum
]

View file

@ -1,4 +1,4 @@
import pixie/fileformats/png, strformat, pngsuite import pixie/fileformats/png, strformat, pngsuite, pixie/common
for file in pngSuiteFiles: for file in pngSuiteFiles:
let let
@ -20,3 +20,10 @@ for channels in 1 .. 4:
components[i] = (x * 16).uint8 components[i] = (x * 16).uint8
data.add(components) data.add(components)
let encoded = encodePng(16, 16, channels, data[0].addr, data.len) let encoded = encodePng(16, 16, channels, data[0].addr, data.len)
for file in pngSuiteCorruptedFiles:
try:
discard decodePng(readFile(&"tests/data/pngsuite/{file}.png"))
doAssert false
except PixieError:
discard