fuzz svg + exceptions
This commit is contained in:
parent
2c08ba2760
commit
4a67ac0625
2 changed files with 34 additions and 12 deletions
|
@ -60,6 +60,7 @@ proc draw(img: Image, matStack: var seq[Mat3], xml: XmlNode) =
|
|||
|
||||
proc decodeSvg*(data: string): Image =
|
||||
## Render SVG file and return the image.
|
||||
try:
|
||||
var xml = parseXml(data)
|
||||
assert xml.tag == "svg"
|
||||
var viewBox = xml.attr "viewBox"
|
||||
|
@ -73,3 +74,7 @@ proc decodeSvg*(data: string): Image =
|
|||
var matStack = @[mat3()]
|
||||
for n in xml:
|
||||
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