Skip to content

Commit f9c7b28

Browse files
Ben WagnerSkia Commit-Bot
authored andcommitted
Add test for old font axis deserialization.
Minimized from fuzzer case (rr is amazing). Verified that this test failed before the fix 712d3a5 "Cannot create SkFontData with no data." and now succeeds with the fix. Bug: oss-fuzz:26254 Change-Id: I985ba3ab61e5824d6a61ede04880692ecc69ce44 Reviewed-on: https://skia-review.googlesource.com/c/skia/+/327916 Reviewed-by: Mike Klein <mtklein@google.com> Commit-Queue: Ben Wagner <bungeman@google.com>
1 parent 8aa0edf commit f9c7b28

File tree

1 file changed

+22
-0
lines changed

1 file changed

+22
-0
lines changed

tests/TypefaceTest.cpp

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,28 @@ DEF_TEST(FontDescriptorNegativeVariationSerialize, reporter) {
149149
REPORTER_ASSERT(reporter, descD.getVariation()[0].value == -1.0f);
150150
};
151151

152+
DEF_TEST(FontDescriptorDeserializeOldFormat, reporter) {
153+
// From ossfuzz:26254
154+
const uint8_t old_serialized_desc[] = {
155+
0x0, //style
156+
0xff, 0xfb, 0x0, 0x0, 0x0, // kFontAxes
157+
0x0, // coordinateCount
158+
0xff, 0xff, 0x0, 0x0, 0x0, // kSentinel
159+
0x0, // data length
160+
};
161+
162+
SkMemoryStream stream(old_serialized_desc, sizeof(old_serialized_desc), false);
163+
SkFontDescriptor desc;
164+
if (!SkFontDescriptor::Deserialize(&stream, &desc)) {
165+
REPORT_FAILURE(reporter, "!SkFontDescriptor::Deserialize(&stream, &desc)",
166+
SkString("bytes should be recognized unless removing support"));
167+
return;
168+
}
169+
// This call should not crash and should not return a valid SkFontData.
170+
std::unique_ptr<SkFontData> data = desc.maybeAsSkFontData();
171+
REPORTER_ASSERT(reporter, !data);
172+
};
173+
152174
DEF_TEST(TypefaceAxes, reporter) {
153175
std::unique_ptr<SkStreamAsset> distortable(GetResourceAsStream("fonts/Distortable.ttf"));
154176
if (!distortable) {

0 commit comments

Comments
 (0)