Guard against divide-by-zero in drawing of last resort

Exit early if there will be a divide by zero or if no pixels are
to be drawn. Report that some glyphs have been excluded.

Bug: oss-fuzz:48695
Bug: oss-fuzz:48690
Change-Id: Ifdb0fad656ffc27bac7253035c7cd05ee96c274c
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/556018
Reviewed-by: Brian Osman <brianosman@google.com>
Commit-Queue: Herb Derby <herb@google.com>
This commit is contained in:
Herb Derby 2022-07-06 10:49:32 -04:00 committed by SkCQ
parent 41a1d5f495
commit 7f8303d25a

View File

@ -2470,7 +2470,7 @@ std::tuple<bool, SubRunContainerOwner> SubRunContainer::MakeInAlloc(
SkASSERT(strikeDeviceInfo.fSDFTControl != nullptr);
if (strikeDeviceInfo.fSDFTControl == nullptr) {
return {true, nullptr};
return {true /* some glyphs excluded */, nullptr};
}
SubRunContainerOwner container{nullptr};
@ -2660,6 +2660,11 @@ std::tuple<bool, SubRunContainerOwner> SubRunContainer::MakeInAlloc(
const SkScalar originalMaxGlyphDimension =
gaugingStrike->findMaximumGlyphDimension(glyphs);
// If there are no pixels to change then don't create a SubRun.
if (originalMaxGlyphDimension == 0) {
return {true /* some glyphs excluded */, nullptr};
}
SkScalar strikeToSourceScale = 1;
SkFont reducedFont = runFont;
if (originalMaxGlyphDimension > kMaxBilerpAtlasDimension) {
@ -2686,6 +2691,11 @@ std::tuple<bool, SubRunContainerOwner> SubRunContainer::MakeInAlloc(
// Remember, this will be an integer.
maxGlyphDimension = reducingStrike->findMaximumGlyphDimension(glyphs);
// Guard against divide-by-zero below.
if (maxGlyphDimension == 0) {
return {true /* some glyphs excluded */, nullptr};
}
// The largest reduction factor allowed for each iteration. Smaller reduction
// factors reduce the font size faster.
static constexpr SkScalar kMaximumReduction =