Skip to content

Commit fed92a3

Browse files
authored
fix(📝): prevent out-of-bounds access in TextPathCmd with unsupported glyphs (#3515)
1 parent 7dd686b commit fed92a3

File tree

1 file changed

+10
-2
lines changed

1 file changed

+10
-2
lines changed

‎packages/skia/cpp/api/recorder/Drawings.h‎

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -246,10 +246,18 @@ class TextPathCmd : public Command {
246246

247247
// Get glyph widths
248248
int glyphsSize = static_cast<int>(ids);
249+
250+
// Validate glyph count
251+
if (glyphsSize > numGlyphIds) {
252+
throw std::runtime_error(
253+
"Glyph count mismatch: got " + std::to_string(glyphsSize) +
254+
" glyphs but expected " + std::to_string(numGlyphIds));
255+
}
256+
249257
std::vector<SkScalar> widthPtrs;
250258
widthPtrs.resize(glyphsSize);
251259
font->getWidthsBounds(
252-
SkSpan(glyphIds.data(), numGlyphIds),
260+
SkSpan(glyphIds.data(), glyphsSize),
253261
SkSpan(static_cast<SkScalar *>(widthPtrs.data()), widthPtrs.size()),
254262
{},
255263
nullptr); // TODO: Should we use paint somehow here?
@@ -260,7 +268,7 @@ class TextPathCmd : public Command {
260268
auto cont = meas.next();
261269
auto dist = initialOffset;
262270

263-
for (size_t i = 0; i < text.length() && cont != nullptr; ++i) {
271+
for (int i = 0; i < glyphsSize && cont != nullptr; ++i) {
264272
auto width = widthPtrs[i];
265273
dist += width / 2;
266274
if (dist > cont->length()) {

0 commit comments

Comments
 (0)