improve GrGlyphVector::MakeFromBuffer's error checking
This fixes a build bot problem. Because this is run with --nonativeFonts, we are building a descriptor that can't be turned into a strike. Make failure to find the strike return an error instead of asserting. In addition, use the proper code idiom for checking condition in other parts of the code. Change-Id: I3fc4051bf93e8f5308ac55bebd4218c04b5a6620 Reviewed-on: https://skia-review.googlesource.com/c/skia/+/511797 Reviewed-by: Robert Phillips <robertphillips@google.com> Commit-Queue: Herb Derby <herb@google.com>
This commit is contained in:
parent
da1de8fa8b
commit
5c2a0f7907
@ -37,25 +37,26 @@ std::optional<GrGlyphVector> GrGlyphVector::MakeFromBuffer(SkReadBuffer& buffer,
|
||||
const SkStrikeClient* client,
|
||||
GrSubRunAllocator* alloc) {
|
||||
auto descriptor = SkAutoDescriptor::MakeFromBuffer(buffer);
|
||||
if (!descriptor.has_value()) { return {}; }
|
||||
if (!buffer.validate(descriptor.has_value())) { return {}; }
|
||||
|
||||
if (client != nullptr) {
|
||||
if (!client->translateTypefaceID(&descriptor.value())) { return {}; }
|
||||
}
|
||||
|
||||
sk_sp<SkStrike> strike = SkStrikeCache::GlobalStrikeCache()->findStrike(*descriptor->getDesc());
|
||||
SkASSERT(strike != nullptr);
|
||||
if (!buffer.validate(strike != nullptr)) { return {}; }
|
||||
|
||||
int32_t glyphCount = buffer.read32();
|
||||
// Since the glyph count can never be zero. There was a buffer reading problem.
|
||||
if (glyphCount == 0) { return {}; }
|
||||
if (!buffer.validate(glyphCount > 0)) { return {}; }
|
||||
|
||||
// Make sure we can multiply without overflow in the check below.
|
||||
if ((int)(INT_MAX / sizeof(uint32_t)) < glyphCount) { return {}; }
|
||||
static constexpr int kMaxCount = (int)(INT_MAX / sizeof(uint32_t));
|
||||
if (!buffer.validate(glyphCount <= kMaxCount)) { return {}; }
|
||||
|
||||
// Check for enough bytes to populate the packedGlyphID array. If not enought something has
|
||||
// Check for enough bytes to populate the packedGlyphID array. If not enough something has
|
||||
// gone wrong.
|
||||
if (glyphCount * sizeof(uint32_t) > buffer.available()) { return {}; }
|
||||
if (!buffer.validate(glyphCount * sizeof(uint32_t) <= buffer.available())) { return {}; }
|
||||
|
||||
Variant* variants = alloc->makePODArray<Variant>(glyphCount);
|
||||
for (int i = 0; i < glyphCount; i++) {
|
||||
|
Loading…
Reference in New Issue
Block a user