runtime check for in-range colortypes
Bug:743106 Change-Id: Ia014643c6f1914cf2b9b873138a0c53a783f666f Reviewed-on: https://skia-review.googlesource.com/23943 Reviewed-by: Florin Malita <fmalita@chromium.org> Commit-Queue: Mike Reed <reed@google.com>
This commit is contained in:
parent
e3e9628ecf
commit
b3d1d90b28
@ -55,15 +55,19 @@ const Stored_SkColorType gLiveToStored[] = {
|
||||
|
||||
static uint8_t live_to_stored(unsigned ct) {
|
||||
static_assert(SK_ARRAY_COUNT(gLiveToStored) == (kLastEnum_SkColorType + 1), "");
|
||||
SkASSERT(ct < SK_ARRAY_COUNT(gLiveToStored));
|
||||
|
||||
if (ct >= SK_ARRAY_COUNT(gLiveToStored)) {
|
||||
ct = kUnknown_SkColorType;
|
||||
}
|
||||
return gLiveToStored[ct];
|
||||
}
|
||||
|
||||
static SkColorType stored_to_live(unsigned stored) {
|
||||
static_assert(SK_ARRAY_COUNT(gStoredToLive) == (kLast_Stored_SkColorType + 1), "");
|
||||
SkASSERT(stored < SK_ARRAY_COUNT(gStoredToLive));
|
||||
|
||||
if (stored >= SK_ARRAY_COUNT(gStoredToLive)) {
|
||||
stored = kUnknown_Stored_SkColorType;
|
||||
}
|
||||
return gStoredToLive[stored];
|
||||
}
|
||||
|
||||
@ -90,7 +94,7 @@ void SkImageInfo::unflatten(SkReadBuffer& buffer) {
|
||||
fHeight = buffer.read32();
|
||||
|
||||
uint32_t packed = buffer.read32();
|
||||
fColorType = stored_to_live((SkColorType)((packed >> 0) & kColorTypeMask));
|
||||
fColorType = stored_to_live((packed >> 0) & kColorTypeMask);
|
||||
fAlphaType = (SkAlphaType)((packed >> 8) & kAlphaTypeMask);
|
||||
buffer.validate(alpha_type_is_valid(fAlphaType) && color_type_is_valid(fColorType));
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user