Properly fill in memory in sampled RLE BMPs
Bug: oss-fuzz:11039
Previously, RLE BMPs were not initialized when they were incomplete,
with the thinking that they were fully initialized at the start of
decoding. While this is true during full decodes (onGetPixels), it is
not true of scanline decodes where we may start with a failing skip.
Remove incorrect comment about creating a sampler in SkBmpRLECodec.
Instead create the sampler when appropriate. Rather than make it
implement its own version of SkSampler::fill, which would look like the
other implementations, add a new virtual method to determine the width
and leave the common implementation to the caller.
Simplify SkCodec::fillIncompleteImage, which always does basically the
same thing.
Change-Id: I885ebb7a0fe5add2a4f59bce57d07d98e4dc1bdb
Reviewed-on: https://skia-review.googlesource.com/c/163484
Reviewed-by: Mike Klein <mtklein@google.com>
Commit-Queue: Leon Scroggins <scroggo@google.com>
diff --git a/src/codec/SkCodec.cpp b/src/codec/SkCodec.cpp
index f9c34dd..dfd1e0a 100644
--- a/src/codec/SkCodec.cpp
+++ b/src/codec/SkCodec.cpp
@@ -559,41 +559,22 @@
}
}
-static void fill_proc(const SkImageInfo& info, void* dst, size_t rowBytes,
- SkCodec::ZeroInitialized zeroInit, SkSampler* sampler) {
- if (sampler) {
- sampler->fill(info, dst, rowBytes, zeroInit);
- } else {
- SkSampler::Fill(info, dst, rowBytes, zeroInit);
- }
-}
-
void SkCodec::fillIncompleteImage(const SkImageInfo& info, void* dst, size_t rowBytes,
ZeroInitialized zeroInit, int linesRequested, int linesDecoded) {
+ if (kYes_ZeroInitialized == zeroInit) {
+ return;
+ }
- void* fillDst;
const int linesRemaining = linesRequested - linesDecoded;
SkSampler* sampler = this->getSampler(false);
- int fillWidth = info.width();
- if (fOptions.fSubset) {
- fillWidth = fOptions.fSubset->width();
- }
-
- switch (this->getScanlineOrder()) {
- case kTopDown_SkScanlineOrder: {
- const SkImageInfo fillInfo = info.makeWH(fillWidth, linesRemaining);
- fillDst = SkTAddOffset<void>(dst, linesDecoded * rowBytes);
- fill_proc(fillInfo, fillDst, rowBytes, zeroInit, sampler);
- break;
- }
- case kBottomUp_SkScanlineOrder: {
- fillDst = dst;
- const SkImageInfo fillInfo = info.makeWH(fillWidth, linesRemaining);
- fill_proc(fillInfo, fillDst, rowBytes, zeroInit, sampler);
- break;
- }
- }
+ const int fillWidth = sampler ? sampler->fillWidth() :
+ fOptions.fSubset ? fOptions.fSubset->width() :
+ info.width() ;
+ void* fillDst = this->getScanlineOrder() == kBottomUp_SkScanlineOrder ? dst :
+ SkTAddOffset<void>(dst, linesDecoded * rowBytes);
+ const auto fillInfo = info.makeWH(fillWidth, linesRemaining);
+ SkSampler::Fill(fillInfo, fillDst, rowBytes, kNo_ZeroInitialized);
}
static inline bool select_xform_format(SkColorType colorType, bool forColorTable,