fuzz svg + exceptions
This commit is contained in:
parent
2c08ba2760
commit
4a67ac0625
2 changed files with 34 additions and 12 deletions
|
@ -60,16 +60,21 @@ proc draw(img: Image, matStack: var seq[Mat3], xml: XmlNode) =
|
||||||
|
|
||||||
proc decodeSvg*(data: string): Image =
|
proc decodeSvg*(data: string): Image =
|
||||||
## Render SVG file and return the image.
|
## Render SVG file and return the image.
|
||||||
var xml = parseXml(data)
|
try:
|
||||||
assert xml.tag == "svg"
|
var xml = parseXml(data)
|
||||||
var viewBox = xml.attr "viewBox"
|
assert xml.tag == "svg"
|
||||||
let box = viewBox.split(" ")
|
var viewBox = xml.attr "viewBox"
|
||||||
assert parseInt(box[0]) == 0
|
let box = viewBox.split(" ")
|
||||||
assert parseInt(box[1]) == 0
|
assert parseInt(box[0]) == 0
|
||||||
let w = parseInt(box[2])
|
assert parseInt(box[1]) == 0
|
||||||
let h = parseInt(box[3])
|
let w = parseInt(box[2])
|
||||||
result = newImage(w, h)
|
let h = parseInt(box[3])
|
||||||
|
result = newImage(w, h)
|
||||||
|
|
||||||
var matStack = @[mat3()]
|
var matStack = @[mat3()]
|
||||||
for n in xml:
|
for n in xml:
|
||||||
result.draw(matStack, n)
|
result.draw(matStack, n)
|
||||||
|
except PixieError as e:
|
||||||
|
raise e
|
||||||
|
except:
|
||||||
|
raise newException(PixieError, "Unable to load SVG")
|
||||||
|
|
17
tests/fuzz_svg.nim
Normal file
17
tests/fuzz_svg.nim
Normal file
|
@ -0,0 +1,17 @@
|
||||||
|
import random, strformat, pixie/fileformats/svg, pixie/common
|
||||||
|
|
||||||
|
randomize()
|
||||||
|
|
||||||
|
let original = readFile("tests/images/svg/Ghostscript_Tiger.svg")
|
||||||
|
|
||||||
|
for i in 0 ..< 10_000:
|
||||||
|
var data = original
|
||||||
|
let
|
||||||
|
pos = rand(data.len)
|
||||||
|
value = rand(255).char
|
||||||
|
data[pos] = value
|
||||||
|
echo &"{i} {pos} {value}"
|
||||||
|
try:
|
||||||
|
discard decodeSvg(data)
|
||||||
|
except PixieError:
|
||||||
|
discard
|
Loading…
Reference in a new issue