| 1 |
From a145861ad1c2650c58dd3ff0dbd92ae6f41f1e1b Mon Sep 17 00:00:00 2001 |
| 2 |
From: Kaylee Lubick <[email protected]> |
| 3 |
Date: Fri, 5 Jun 2026 20:51:04 +0000 |
| 4 |
Subject: [PATCH] Reject Slugs that have creationMatrix with perspective |
| 5 |
|
| 6 |
This shouldn't happen during normal use [1] but if the data |
| 7 |
is corrupted, there are some assumptions that can can cause |
| 8 |
issues, like the ones linked in the bug. |
| 9 |
|
| 10 |
This rejects those and turns one assert into an actual runtime |
| 11 |
check to provide defense in depth. |
| 12 |
|
| 13 |
[1] https://github.com/google/skia/blob/9eecbdc30f7da675edab96974b23174a9d521e0c/src/text/gpu/SubRunContainer.cpp#L1578-L1581 |
| 14 |
|
| 15 |
Bug: https://issues.chromium.org/issues/520113415 |
| 16 |
Fixed: 520113415 |
| 17 |
Change-Id: I6ec23df9a23ea588fa89f7a62dc1f197fe3905fd |
| 18 |
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/1256016 |
| 19 |
Commit-Queue: Kaylee Lubick <[email protected]> |
| 20 |
Reviewed-by: Thomas Smith <[email protected]> |
| 21 |
--- |
| 22 |
src/gpu/ganesh/ops/AtlasTextOp.cpp | 15 ++++-- |
| 23 |
src/text/gpu/SubRunContainer.cpp | 5 ++ |
| 24 |
tests/SlugTest.cpp | 85 ++++++++++++++++++++++++++++++ |
| 25 |
3 files changed, 100 insertions(+), 5 deletions(-) |
| 26 |
|
| 27 |
--- a/src/gpu/ganesh/ops/AtlasTextOp.cpp |
| 28 |
+++ b/src/gpu/ganesh/ops/AtlasTextOp.cpp |
| 29 |
@@ -523,9 +523,17 @@ |
| 30 |
|
| 31 |
for (const Geometry* geo = fHead; geo != nullptr; geo = geo->fNext) { |
| 32 |
const sktext::gpu::AtlasSubRun& subRun = geo->fSubRun; |
| 33 |
- SkASSERTF((int) subRun.vertexStride(geo->fDrawMatrix) == vertexStride, |
| 34 |
- "subRun stride: %d vertex buffer stride: %d\n", |
| 35 |
- (int)subRun.vertexStride(geo->fDrawMatrix), vertexStride); |
| 36 |
+ |
| 37 |
+ int strideCheck = SkToInt(subRun.vertexStride(geo->fDrawMatrix)); |
| 38 |
+ if (strideCheck != vertexStride) { |
| 39 |
+ // We (unexpectedly) have buffers of different sizes between CPU and GPU. Bail out. |
| 40 |
+ SKIA_LOG_D( |
| 41 |
+ "Warning: stride mismatch detected (subrun stride: %d vertex buffer stride: " |
| 42 |
+ "%d). Aborting draw.\n", |
| 43 |
+ strideCheck, |
| 44 |
+ vertexStride); |
| 45 |
+ return; |
| 46 |
+ } |
| 47 |
|
| 48 |
const int subRunEnd = subRun.glyphCount(); |
| 49 |
auto regenerateDelegate = [&](sktext::gpu::GlyphVector* glyphs, |
| 50 |
--- a/src/text/gpu/SubRunContainer.cpp |
| 51 |
+++ b/src/text/gpu/SubRunContainer.cpp |
| 52 |
@@ -169,6 +169,11 @@ |
| 53 |
|
| 54 |
SkMatrix creationMatrix; |
| 55 |
buffer.readMatrix(&creationMatrix); |
| 56 |
+ // The only valid creationMatrices do not have perspective and many rendering parts assume |
| 57 |
+ // they are non-affine, so reject any malformed matrices here. |
| 58 |
+ if (!buffer.validate(!creationMatrix.hasPerspective())) { |
| 59 |
+ return std::nullopt; |
| 60 |
+ } |
| 61 |
|
| 62 |
SkSpan<SkPoint> leftTop = make_points_from_buffer(buffer, alloc); |
| 63 |
if (leftTop.empty()) { |