static bool ValidArgs(const Info& info, size_t rowBytes) { const int maxDimension = SK_MaxS32 >> 2; const size_t kMaxPixelByteSize = SK_MaxS32; if (info.fWidth < 0 || info.fHeight < 0) { return false; } if (info.fWidth > maxDimension || info.fHeight > maxDimension) { return false; } if ((unsigned)info.fColorType > (unsigned)kLastEnum_ColorType) { return false; } if ((unsigned)info.fAlphaType > (unsigned)kLastEnum_AlphaType) { return false; } bool isOpaque; if (SkImageInfoToBitmapConfig(info, &isOpaque) == SkBitmap::kNo_Config) { return false; } // TODO: check colorspace if (rowBytes < SkImageMinRowBytes(info)) { return false; } int64_t size = (int64_t)info.fHeight * rowBytes; if (size > (int64_t)kMaxPixelByteSize) { return false; } return true; }
static bool ValidArgs(const Info& info, size_t rowBytes) { const int maxDimension = SK_MaxS32 >> 2; const size_t kMaxPixelByteSize = SK_MaxS32; if (info.fWidth < 0 || info.fHeight < 0) { return false; } if (info.fWidth > maxDimension || info.fHeight > maxDimension) { return false; } if ((unsigned)info.fColorType > (unsigned)kLastEnum_SkColorType) { return false; } if ((unsigned)info.fAlphaType > (unsigned)kLastEnum_SkAlphaType) { return false; } if (kUnknown_SkColorType == info.colorType()) { return false; } // TODO: check colorspace if (rowBytes < SkImageMinRowBytes(info)) { return false; } int64_t size = (int64_t)info.fHeight * rowBytes; if (size > (int64_t)kMaxPixelByteSize) { return false; } return true; }
static bool ValidArgs(const Info& info, size_t rowBytes, bool hasColorTable, size_t* minSize) { const int maxDimension = SK_MaxS32 >> 2; if (info.width() <= 0 || info.height() <= 0) { return false; } if (info.width() > maxDimension || info.height() > maxDimension) { return false; } if ((unsigned)info.colorType() > (unsigned)kLastEnum_SkColorType) { return false; } if ((unsigned)info.alphaType() > (unsigned)kLastEnum_SkAlphaType) { return false; } if (kUnknown_SkColorType == info.colorType()) { return false; } const bool needsCT = kIndex_8_SkColorType == info.colorType(); if (needsCT != hasColorTable) { return false; } if (rowBytes < SkImageMinRowBytes(info)) { return false; } size_t size = info.getSafeSize(rowBytes); if (0 == size) { return false; } if (minSize) { *minSize = size; } return true; }