Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(74)

Unified Diff: src/core/SkImageInfo.cpp

Issue 2110493002: Tighten up masking of colorType & alphaType in SkImageInfo serialization (for fuzzer bug) (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Created 4 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/core/SkImageInfo.cpp
diff --git a/src/core/SkImageInfo.cpp b/src/core/SkImageInfo.cpp
index b3b9c385d8a13eaf14fe78d11f8393c07bb924ed..75c6807d17fca1a371954dba79ced7a56fd6e107 100644
--- a/src/core/SkImageInfo.cpp
+++ b/src/core/SkImageInfo.cpp
@@ -22,14 +22,16 @@ SkImageInfo SkImageInfo::MakeS32(int width, int height, SkAlphaType at) {
SkColorSpace::NewNamed(SkColorSpace::kSRGB_Named));
}
+static const int kColorTypeMask = 0x0F;
+static const int kAlphaTypeMask = 0x03;
+
void SkImageInfo::unflatten(SkReadBuffer& buffer) {
fWidth = buffer.read32();
fHeight = buffer.read32();
uint32_t packed = buffer.read32();
- SkASSERT(0 == (packed >> 24));
- fColorType = (SkColorType)((packed >> 0) & 0xFF);
- fAlphaType = (SkAlphaType)((packed >> 8) & 0xFF);
+ fColorType = (SkColorType)((packed >> 0) & kColorTypeMask);
+ fAlphaType = (SkAlphaType)((packed >> 8) & kAlphaTypeMask);
buffer.validate(alpha_type_is_valid(fAlphaType) && color_type_is_valid(fColorType));
sk_sp<SkData> data = buffer.readByteArrayAsData();
@@ -40,8 +42,8 @@ void SkImageInfo::flatten(SkWriteBuffer& buffer) const {
buffer.write32(fWidth);
buffer.write32(fHeight);
- SkASSERT(0 == (fAlphaType & ~0xFF));
- SkASSERT(0 == (fColorType & ~0xFF));
+ SkASSERT(0 == (fAlphaType & ~kAlphaTypeMask));
+ SkASSERT(0 == (fColorType & ~kColorTypeMask));
uint32_t packed = (fAlphaType << 8) | fColorType;
buffer.write32(packed);
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698