| 1 |
From e202cf3ef8e18c0f47f1d7098fb96efbdc1953c1 Mon Sep 17 00:00:00 2001 |
| 2 |
From: Kaylee Lubick <[email protected]> |
| 3 |
Date: Fri, 29 May 2026 15:16:50 -0400 |
| 4 |
Subject: [PATCH] Address potential MSAN issue in SkScalerContext |
| 5 |
|
| 6 |
If malformed data was passed to SkStrikeClient, an unexpected |
| 7 |
mask would pass through asserts in a release build and lead |
| 8 |
to a mask being allocated that was 4x bigger than what |
| 9 |
was written to. |
| 10 |
|
| 11 |
To defend against this problem, we 1) reject masks that |
| 12 |
aren't of the three formats SkScalerContext::GenerateImageFromPath |
| 13 |
expects; 2) zero out the whole mask, regardless of how big |
| 14 |
it is instead of relying on how big an A8 mask would be. |
| 15 |
|
| 16 |
Additionally, I noticed that in the intermediateDst case |
| 17 |
(e.g. for LCD text when we draw into an A8 and then later unpack |
| 18 |
it to be LCD16) we weren't zeroing that intermediate buffer |
| 19 |
which could be a problem if the glyph itself was small (but |
| 20 |
the bounds were corrupted to be big). Thus, we zero that |
| 21 |
intermediate A8 buffer too. |
| 22 |
|
| 23 |
Change-Id: Ib7080fc45eb77ea19b3e733570da33cd339a51f8 |
| 24 |
Bug: https://issues.chromium.org/issues/513780208 |
| 25 |
Fixed: 513780208 |
| 26 |
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/1248536 |
| 27 |
Commit-Queue: Kaylee Lubick <[email protected]> |
| 28 |
Auto-Submit: Kaylee Lubick <[email protected]> |
| 29 |
Reviewed-by: Florin Malita <[email protected]> |
| 30 |
--- |
| 31 |
src/core/SkGlyph.cpp | 6 +++ |
| 32 |
src/core/SkScalerContext.cpp | 4 +- |
| 33 |
tests/SkRemoteGlyphCacheTest.cpp | 86 ++++++++++++++++++++++++++++++++ |
| 34 |
3 files changed, 95 insertions(+), 1 deletion(-) |
| 35 |
|
| 36 |
diff --git a/src/core/SkGlyph.cpp b/src/core/SkGlyph.cpp |
| 37 |
index 26c8004256..7f440a4dfd 100644 |
| 38 |
--- a/src/core/SkGlyph.cpp |
| 39 |
+++ b/src/core/SkGlyph.cpp |
| 40 |
@@ -406,6 +406,12 @@ size_t SkGlyph::addPathFromBuffer(SkReadBuffer& buffer, SkArenaAlloc* alloc) { |
| 41 |
const bool pathIsHairline = buffer.readBool(); |
| 42 |
const bool pathIsModified = buffer.readBool(); |
| 43 |
if (auto path = buffer.readPath()) { |
| 44 |
+ if (fMaskFormat != SkMask::kBW_Format && |
| 45 |
+ fMaskFormat != SkMask::kA8_Format && |
| 46 |
+ fMaskFormat != SkMask::kLCD16_Format) { |
| 47 |
+ buffer.validate(false); |
| 48 |
+ return 0; |
| 49 |
+ } |
| 50 |
if (this->setPath(alloc, &path.value(), pathIsHairline, pathIsModified)) { |
| 51 |
memoryIncrease += path->approximateBytesUsed(); |
| 52 |
} |
| 53 |
diff --git a/src/core/SkScalerContext.cpp b/src/core/SkScalerContext.cpp |
| 54 |
index 85edc26a3f..2d68c145f0 100644 |
| 55 |
--- a/src/core/SkScalerContext.cpp |
| 56 |
+++ b/src/core/SkScalerContext.cpp |
| 57 |
@@ -572,10 +572,11 @@ void SkScalerContext::GenerateImageFromPath( |
| 58 |
sk_bzero(dstMask.image(), dstMask.computeImageSize()); |
| 59 |
return; |
| 60 |
} |
| 61 |
+ sk_bzero(dst.writable_addr(), dst.computeByteSize()); |
| 62 |
} else { |
| 63 |
dst.reset(info, dstMask.image(), dstMask.fRowBytes); |
| 64 |
} |
| 65 |
- sk_bzero(dst.writable_addr(), dst.computeByteSize()); |
| 66 |
+ sk_bzero(dstMask.image(), dstMask.computeImageSize()); |
| 67 |
|
| 68 |
skcpu::Draw draw; |
| 69 |
draw.fBlitterChooser = SkA8Blitter_Choose; |
| 70 |
@@ -600,6 +601,7 @@ void SkScalerContext::GenerateImageFromPath( |
| 71 |
pack4xHToMask(dst, dstMask, maskPreBlend, doBGR, verticalLCD); |
| 72 |
break; |
| 73 |
default: |
| 74 |
+ SkUNREACHABLE; |
| 75 |
break; |
| 76 |
} |
| 77 |
} |
| 78 |
-- |
| 79 |
2.53.0 |
| 80 |
|