Skip to content

Commit eb8759b

Browse files
fmalitaSkCQ
authored andcommitted
Range-check custom typeface glyph ids
Bug: b/375261949 Change-Id: I52f17360ab88d8a9dd99aa4d85be64f34b991064 Reviewed-on: https://skia-review.googlesource.com/c/skia/+/913336 Reviewed-by: Ben Wagner <[email protected]> Reviewed-by: Florin Malita <[email protected]> Commit-Queue: Florin Malita <[email protected]>
1 parent 98a0689 commit eb8759b

File tree

2 files changed

+27
-2
lines changed

2 files changed

+27
-2
lines changed

src/utils/SkCustomTypeface.cpp

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -259,9 +259,15 @@ class SkUserScalerContext : public SkScalerContext {
259259
GlyphMetrics mx(glyph.maskFormat());
260260

261261
const SkUserTypeface* tf = this->userTF();
262-
mx.advance = fMatrix.mapXY(tf->fGlyphRecs[glyph.getGlyphID()].fAdvance, 0);
262+
const SkGlyphID gid = glyph.getGlyphID();
263+
if (gid >= tf->fGlyphRecs.size()) {
264+
mx.neverRequestPath = true;
265+
return mx;
266+
}
267+
268+
const auto& rec = tf->fGlyphRecs[gid];
269+
mx.advance = fMatrix.mapXY(rec.fAdvance, 0);
263270

264-
const auto& rec = tf->fGlyphRecs[glyph.getGlyphID()];
265271
if (rec.isDrawable()) {
266272
mx.maskFormat = SkMask::kARGB32_Format;
267273

tests/TypefaceTest.cpp

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
#include "include/core/SkData.h"
99
#include "include/core/SkFont.h"
1010
#include "include/core/SkFontArguments.h"
11+
#include "include/core/SkFontMetrics.h"
1112
#include "include/core/SkFontMgr.h"
1213
#include "include/core/SkFontParameters.h"
1314
#include "include/core/SkFontStyle.h"
@@ -20,6 +21,7 @@
2021
#include "include/core/SkTypes.h"
2122
#include "include/private/base/SkFixed.h"
2223
#include "include/private/base/SkTemplates.h"
24+
#include "include/utils/SkCustomTypeface.h"
2325
#include "src/base/SkEndian.h"
2426
#include "src/base/SkUTF.h"
2527
#include "src/core/SkFontDescriptor.h"
@@ -710,3 +712,20 @@ DEF_TEST(LegacyMakeTypeface, reporter) {
710712
REPORTER_ASSERT(reporter, typeface3->isBold());
711713
}
712714
}
715+
716+
DEF_TEST(CustomTypeface_invalid_glyphid, reporter) {
717+
SkPath glyph_path;
718+
glyph_path.addRect({10, 20, 30, 40});
719+
720+
SkCustomTypefaceBuilder builder;
721+
builder.setGlyph(0, 42, glyph_path);
722+
723+
SkFont custom_font(builder.detach(), 1);
724+
725+
SkGlyphID glyph_ids[] = {0, 1};
726+
SkRect bounds[2];
727+
custom_font.getBounds(glyph_ids, 2, bounds, nullptr);
728+
729+
REPORTER_ASSERT(reporter, bounds[0] == SkRect::MakeLTRB(10, 20, 30, 40));
730+
REPORTER_ASSERT(reporter, bounds[1] == SkRect::MakeLTRB(0, 0, 0, 0));
731+
}

0 commit comments

Comments
 (0)