Add test for bad reuse of SkJpegCodec internal state

This is a test for the following fix:
https://skia-review.googlesource.com/c/7451/

b/34637813

Change-Id: I3fdb0d7d50537948039b75c3a22454e789ca810a
Reviewed-on: https://skia-review.googlesource.com/7454
Commit-Queue: Matt Sarett <msarett@google.com>
Reviewed-by: Leon Scroggins <scroggo@google.com>
diff --git a/tests/CodecTest.cpp b/tests/CodecTest.cpp
index 8294c7a..f0d60e7 100644
--- a/tests/CodecTest.cpp
+++ b/tests/CodecTest.cpp
@@ -1018,11 +1018,28 @@
     // Perform a sampled decode.
     SkAndroidCodec::AndroidOptions opts;
     opts.fSampleSize = 12;
-    codec->getAndroidPixels(codec->getInfo().makeWH(width / 12, height / 12), pixelStorage.get(),
-                            rowBytes, &opts);
+    SkCodec::Result result = codec->getAndroidPixels(
+            codec->getInfo().makeWH(width / 12, height / 12), pixelStorage.get(), rowBytes, &opts);
+    REPORTER_ASSERT(r, SkCodec::kSuccess == result);
 
     // Rewind the codec and perform a full image decode.
-    SkCodec::Result result = codec->getPixels(codec->getInfo(), pixelStorage.get(), rowBytes);
+    result = codec->getPixels(codec->getInfo(), pixelStorage.get(), rowBytes);
+    REPORTER_ASSERT(r, SkCodec::kSuccess == result);
+
+    // Now perform a subset decode.
+    {
+        opts.fSampleSize = 1;
+        SkIRect subset = SkIRect::MakeWH(100, 100);
+        opts.fSubset = &subset;
+        result = codec->getAndroidPixels(codec->getInfo().makeWH(100, 100), pixelStorage.get(),
+                                         rowBytes, &opts);
+        REPORTER_ASSERT(r, SkCodec::kSuccess == result);
+    }
+
+    // Perform another full image decode.  ASAN will detect if we look at the subset when it is
+    // out of scope.  This would happen if we depend on the old state in the codec.
+    opts.fSubset = nullptr;
+    result = codec->getAndroidPixels(codec->getInfo(), pixelStorage.get(), rowBytes, &opts);
     REPORTER_ASSERT(r, SkCodec::kSuccess == result);
 }