SkCodec: don't assume frameRect is valid

Bug: skia:9321

frameRect is the raw data stored in the image file, and it may not
intersect with the image's canvas. Remove that assumption.

Change-Id: I12802c9c20c0cb3506e64e14b129650ef0767f95
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/233157
Auto-Submit: Leon Scroggins <scroggo@google.com>
Commit-Queue: Kevin Lubick <kjlubick@google.com>
Reviewed-by: Nigel Tao <nigeltao@google.com>
Reviewed-by: Kevin Lubick <kjlubick@google.com>
This commit is contained in:
Leon Scroggins III 2019-08-07 16:42:04 -04:00 committed by Skia Commit-Bot
parent 241e0ee4a7
commit 19e3cd4c9c

View File

@ -205,8 +205,21 @@ bool SkCodec::rewindIfNeeded() {
return this->onRewind();
}
static SkIRect frame_rect_on_screen(SkIRect frameRect,
const SkIRect& screenRect) {
if (!frameRect.intersect(screenRect)) {
return SkIRect::MakeEmpty();
}
return frameRect;
}
bool zero_rect(const SkImageInfo& dstInfo, void* pixels, size_t rowBytes,
SkISize srcDimensions, SkIRect prevRect) {
prevRect = frame_rect_on_screen(prevRect, SkIRect::MakeSize(srcDimensions));
if (prevRect.isEmpty()) {
return true;
}
const auto dimensions = dstInfo.dimensions();
if (dimensions != srcDimensions) {
SkRect src = SkRect::Make(srcDimensions);
@ -224,12 +237,6 @@ bool zero_rect(const SkImageInfo& dstInfo, void* pixels, size_t rowBytes,
}
}
if (!prevRect.intersect(dstInfo.bounds())) {
SkCodecPrintf("rectangles do not intersect!");
SkASSERT(false);
return true;
}
const SkImageInfo info = dstInfo.makeWH(prevRect.width(), prevRect.height());
const size_t bpp = dstInfo.bytesPerPixel();
const size_t offset = prevRect.x() * bpp + prevRect.y() * rowBytes;
@ -725,15 +732,6 @@ const char* SkCodec::ResultToString(Result result) {
}
}
static SkIRect frame_rect_on_screen(SkIRect frameRect,
const SkIRect& screenRect) {
if (!frameRect.intersect(screenRect)) {
return SkIRect::MakeEmpty();
}
return frameRect;
}
static bool independent(const SkFrame& frame) {
return frame.getRequiredFrame() == SkCodec::kNoFrame;
}