| 1 |
From 8ac48d9b53de0287c171093d751e8db180c641cf Mon Sep 17 00:00:00 2001 |
| 2 |
From: Kaylee Lubick <[email protected]> |
| 3 |
Date: Mon, 27 Apr 2026 19:58:02 +0000 |
| 4 |
Subject: [PATCH] Identify overflow in SkGlyph allocation earlier |
| 5 |
|
| 6 |
Follow-up to https://review.skia.org/1209996 |
| 7 |
|
| 8 |
Bug: https://issues.chromium.org/issues/499152771 |
| 9 |
Change-Id: I487f64d92aa7177a84c1754e275852373a3cc40e |
| 10 |
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/1219717 |
| 11 |
Commit-Queue: Kaylee Lubick <[email protected]> |
| 12 |
Reviewed-by: Michael Ludwig <[email protected]> |
| 13 |
--- |
| 14 |
src/text/gpu/GlyphVector.cpp | 6 +++--- |
| 15 |
1 file changed, 3 insertions(+), 3 deletions(-) |
| 16 |
|
| 17 |
--- a/src/text/gpu/GlyphVector.cpp |
| 18 |
+++ b/src/text/gpu/GlyphVector.cpp |
| 19 |
@@ -62,14 +62,14 @@ |
| 20 |
return std::nullopt; |
| 21 |
} |
| 22 |
|
| 23 |
- // Make sure we can multiply without overflow in the check below. |
| 24 |
- static constexpr int kMaxCount = (int)(INT_MAX / sizeof(uint32_t)); |
| 25 |
- if (!buffer.validate(glyphCount <= kMaxCount)) { |
| 26 |
+ // Make sure we won't overflow the glyphCount math or allocation below. |
| 27 |
+ if (!buffer.validate(BagOfBytes::WillCountFit<Variant>(glyphCount))) { |
| 28 |
return std::nullopt; |
| 29 |
} |
| 30 |
|
| 31 |
// Check for enough bytes to populate the packedGlyphID array. If not enough something has |
| 32 |
// gone wrong. |
| 33 |
+ static_assert(sizeof(Variant) >= sizeof(uint32_t)); |
| 34 |
if (!buffer.validate(glyphCount * sizeof(uint32_t) <= buffer.available())) { |
| 35 |
return std::nullopt; |
| 36 |
} |