Merge cherrypicks of ['googleplex-android-review.googlesource.com/31416176'] into security-aosp-tm-release.

Change-Id: I1fc81f96dbc8421e0338f5a02fd70b785c04d924
diff --git a/resources/images/bmp-size-32x32-8bpp.bmp b/resources/images/bmp-size-32x32-8bpp.bmp
new file mode 100644
index 0000000..d2f800d
--- /dev/null
+++ b/resources/images/bmp-size-32x32-8bpp.bmp
Binary files differ
diff --git a/src/codec/SkBmpStandardCodec.cpp b/src/codec/SkBmpStandardCodec.cpp
index 07f373b..898cdda 100644
--- a/src/codec/SkBmpStandardCodec.cpp
+++ b/src/codec/SkBmpStandardCodec.cpp
@@ -180,7 +180,7 @@
 
     SkImageInfo swizzlerInfo = dstInfo;
     SkCodec::Options swizzlerOptions = opts;
-    if (this->colorXform()) {
+    if (this->xformOnDecode()) {
         swizzlerInfo = swizzlerInfo.makeColorType(kXformSrcColorType);
         if (kPremul_SkAlphaType == dstInfo.alphaType()) {
             swizzlerInfo = swizzlerInfo.makeAlphaType(kUnpremul_SkAlphaType);
diff --git a/tests/CodecTest.cpp b/tests/CodecTest.cpp
index cd55b14..89c4149 100644
--- a/tests/CodecTest.cpp
+++ b/tests/CodecTest.cpp
@@ -41,6 +41,7 @@
 #include "include/utils/SkRandom.h"
 #include "src/codec/SkCodecImageGenerator.h"
 #include "src/core/SkAutoMalloc.h"
+#include "src/core/SkAutoPixmapStorage.h"
 #include "src/core/SkColorSpacePriv.h"
 #include "src/core/SkMD5.h"
 #include "src/core/SkStreamPriv.h"
@@ -1921,3 +1922,26 @@
         REPORTER_ASSERT(r, bm.getColor(0, 0) == rec.color);
     }
 }
+
+DEF_TEST(Codec_bmp_indexed_colorxform, r) {
+    constexpr char path[] = "images/bmp-size-32x32-8bpp.bmp";
+    std::unique_ptr<SkStream> stream(GetResourceAsStream(path));
+    if (!stream) {
+        SkDebugf("Missing resource '%s'\n", path);
+        return;
+    }
+
+    std::unique_ptr<SkCodec> codec = SkCodec::MakeFromStream(std::move(stream));
+    REPORTER_ASSERT(r, codec);
+
+    // decode to a < 32bpp buffer with a color transform
+    const SkImageInfo decodeInfo = codec->getInfo().makeColorType(kRGB_565_SkColorType)
+                                                   .makeColorSpace(SkColorSpace::MakeSRGBLinear());
+    SkAutoPixmapStorage aps;
+    aps.alloc(decodeInfo);
+
+    // should not crash
+    auto res = codec->getPixels(aps);
+
+    REPORTER_ASSERT(r, res == SkCodec::kSuccess);
+}