From b6c11191723d6eb884de5ee17d658298f5dd4127 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Konstantin=20K=C3=A4fer?= Date: Fri, 13 Jan 2017 12:02:04 +0100 Subject: [core] harden Glyph PBF parsing --- test/fixtures/resources/fake_glyphs-0-255.pbf | Bin 0 -> 432 bytes test/fixtures/resources/fake_glyphs-0-255.pbf.txt | 86 ++++++++++++++++++++++ test/fixtures/resources/fake_glyphs.proto | 31 ++++++++ 3 files changed, 117 insertions(+) create mode 100644 test/fixtures/resources/fake_glyphs-0-255.pbf create mode 100644 test/fixtures/resources/fake_glyphs-0-255.pbf.txt create mode 100644 test/fixtures/resources/fake_glyphs.proto (limited to 'test/fixtures') diff --git a/test/fixtures/resources/fake_glyphs-0-255.pbf b/test/fixtures/resources/fake_glyphs-0-255.pbf new file mode 100644 index 0000000000..8d7445d5c2 Binary files /dev/null and b/test/fixtures/resources/fake_glyphs-0-255.pbf differ diff --git a/test/fixtures/resources/fake_glyphs-0-255.pbf.txt b/test/fixtures/resources/fake_glyphs-0-255.pbf.txt new file mode 100644 index 0000000000..6433af5d3d --- /dev/null +++ b/test/fixtures/resources/fake_glyphs-0-255.pbf.txt @@ -0,0 +1,86 @@ +# Make changes below, then run this command to update the encoded PBF file: +# protoc --encode glyphs test/fixtures/resources/fake_glyphs.proto < test/fixtures/resources/fake_glyphs-0-255.pbf.txt > test/fixtures/resources/fake_glyphs-0-255.pbf + +stacks { + # testing invalid metrics and bitmap too short + glyphs { + id: 65 + bitmap: "fake" + width: -1 + height: 65536 + left: -10000000 + top: 10000000 + advance: -42 + } + + # testing missing bitmap => malformed + glyphs { + id: 66 + width: 12 + height: 17 + left: 2 + top: -11 + advance: 15 + } + + # testing bitmap too long => malformed + glyphs { + id: 67 + bitmap: "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx" + width: 1 + height: 1 + } + + # testing missing ID => malformed + glyphs { + width: 12 + height: 17 + left: 2 + top: -11 + advance: 15 + } + + # invalid metrics + bitmap => malformed + glyphs { + id: 65 + bitmap: "fake" + width: -1 + height: 65536 + left: -10000000 + top: 10000000 + advance: -42 + } + + # invalid metrics => malformed + glyphs { + id: 68 + bitmap: "x" + width: 1 + height: 1 + left: -10000000 + top: 10000000 + advance: -42 + } + + # a valid glyph + glyphs { + id: 69 + bitmap: "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx" + width: 1 + height: 1 + left: 20 + top: 2 + advance: 8 + } + + # a valid glyph that has an ID outside the range + glyphs { + id: 300 + bitmap: "" + width: 0 + height: 0 + left: 0 + top: 0 + advance: 0 + } +} diff --git a/test/fixtures/resources/fake_glyphs.proto b/test/fixtures/resources/fake_glyphs.proto new file mode 100644 index 0000000000..d074541d69 --- /dev/null +++ b/test/fixtures/resources/fake_glyphs.proto @@ -0,0 +1,31 @@ +syntax = "proto2"; + +option optimize_for = LITE_RUNTIME; + +// Stores a glyph with metrics and optional SDF bitmap information. +message glyph { + optional int64 id = 1; + + // A signed distance field of the glyph with a border of 3 pixels. + optional bytes bitmap = 2; + + // Glyph metrics. + optional int64 width = 3; + optional int64 height = 4; + optional sint64 left = 5; + optional sint64 top = 6; + optional int64 advance = 7; +} + +// Stores fontstack information and a list of faces. +message fontstack { + optional string name = 1; + optional string range = 2; + repeated glyph glyphs = 3; +} + +message glyphs { + repeated fontstack stacks = 1; + + extensions 16 to 8191; +} -- cgit v1.2.1