fuzz opentype
This commit is contained in:
parent
267294a3e8
commit
9d2dc5c06f
7
tests/common.nim
Normal file
7
tests/common.nim
Normal file
|
@ -0,0 +1,7 @@
|
||||||
|
import algorithm, os
|
||||||
|
|
||||||
|
proc findAllFonts*(rootPath: string): seq[string] =
|
||||||
|
for fontPath in walkDirRec(rootPath):
|
||||||
|
if splitFile(fontPath).ext in [".ttf", ".otf"]:
|
||||||
|
result.add(fontPath)
|
||||||
|
result.sort()
|
32
tests/fuzz_opentype.nim
Normal file
32
tests/fuzz_opentype.nim
Normal file
|
@ -0,0 +1,32 @@
|
||||||
|
import common, random, pixie, strformat, unicode
|
||||||
|
|
||||||
|
randomize()
|
||||||
|
|
||||||
|
let fontPaths = findAllFonts("tests/fonts")
|
||||||
|
|
||||||
|
doAssert fontPaths.len > 0
|
||||||
|
|
||||||
|
for i in 0 ..< 10000:
|
||||||
|
var
|
||||||
|
file = fontPaths[rand(fontPaths.len - 1)]
|
||||||
|
data = readFile(file)
|
||||||
|
pos = rand(data.len)
|
||||||
|
value = rand(255).char
|
||||||
|
data[pos] = value
|
||||||
|
echo &"{i} {file} {pos} {value.uint8}"
|
||||||
|
try:
|
||||||
|
let font = parseOtf(data)
|
||||||
|
doAssert font != nil
|
||||||
|
for i in 0.uint16 ..< uint16.high:
|
||||||
|
discard font.getGlyphPath(Rune(i.int))
|
||||||
|
except PixieError:
|
||||||
|
discard
|
||||||
|
|
||||||
|
data = data[0 ..< pos]
|
||||||
|
try:
|
||||||
|
let font = parseOtf(data)
|
||||||
|
doAssert font != nil
|
||||||
|
for i in 0.uint16 ..< uint16.high:
|
||||||
|
discard font.getGlyphPath(Rune(i.int))
|
||||||
|
except PixieError:
|
||||||
|
discard
|
Loading…
Reference in a new issue