[RESTRICT AUTOMERGE] CTS test for Android Security b/118372692

Bug: 118372692
Bug: 126635297
Test: Ran the new testcase on android-8.0.0_r2 with/without patch

Merged-In: I5d14ada2af63a926edcde4aec678c2e2a714f92f
Change-Id: I5d14ada2af63a926edcde4aec678c2e2a714f92f
diff --git a/hostsidetests/securitybulletin/AndroidTest.xml b/hostsidetests/securitybulletin/AndroidTest.xml
index 9faf125..45503e6 100644
--- a/hostsidetests/securitybulletin/AndroidTest.xml
+++ b/hostsidetests/securitybulletin/AndroidTest.xml
@@ -222,6 +222,11 @@
         <option name="push" value="CVE-2018-9491->/data/local/tmp/CVE-2018-9491" />
 
         <!--__________________-->
+        <!-- Bulletin 2019-02 -->
+        <!-- Please add tests solely from this bulletin below to avoid merge conflict -->
+        <option name="push" value="CVE-2019-1988->/data/local/tmp/CVE-2019-1988" />
+
+        <!--__________________-->
         <!-- Bulletin 2019-03 -->
         <!-- Please add tests solely from this bulletin below to avoid merge conflict -->
         <option name="push" value="Bug-115739809->/data/local/tmp/Bug-115739809" />
diff --git a/hostsidetests/securitybulletin/res/cve_2019_1988.mp4 b/hostsidetests/securitybulletin/res/cve_2019_1988.mp4
new file mode 100644
index 0000000..cdff65b
--- /dev/null
+++ b/hostsidetests/securitybulletin/res/cve_2019_1988.mp4
Binary files differ
diff --git a/hostsidetests/securitybulletin/securityPatch/CVE-2019-1988/Android.mk b/hostsidetests/securitybulletin/securityPatch/CVE-2019-1988/Android.mk
new file mode 100644
index 0000000..cd4f390
--- /dev/null
+++ b/hostsidetests/securitybulletin/securityPatch/CVE-2019-1988/Android.mk
@@ -0,0 +1,35 @@
+# Copyright (C) 2020 The Android Open Source Project
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+#      http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License
+
+LOCAL_PATH := $(call my-dir)
+include $(CLEAR_VARS)
+
+LOCAL_MODULE := CVE-2019-1988
+LOCAL_SRC_FILES := poc.cpp
+LOCAL_SRC_FILES += ../includes/memutils.c
+LOCAL_MULTILIB := both
+LOCAL_MODULE_STEM_32 := $(LOCAL_MODULE)32
+LOCAL_MODULE_STEM_64 := $(LOCAL_MODULE)64
+LOCAL_C_INCLUDES := external/skia/include/codec
+LOCAL_C_INCLUDES += external/skia/include/core
+LOCAL_C_INCLUDES += external/skia/include/config
+LOCAL_SHARED_LIBRARIES := libskia
+
+# Tag this module as a cts test artifact
+LOCAL_COMPATIBILITY_SUITE := cts sts vts
+LOCAL_CTS_TEST_PACKAGE := android.security.cts
+
+LOCAL_ARM_MODE := arm
+LOCAL_CFLAGS := -Wall -Werror -DCHECK_OVERFLOW -DENABLE_SELECTIVE_OVERLOADING
+include $(BUILD_CTS_EXECUTABLE)
diff --git a/hostsidetests/securitybulletin/securityPatch/CVE-2019-1988/poc.cpp b/hostsidetests/securitybulletin/securityPatch/CVE-2019-1988/poc.cpp
new file mode 100644
index 0000000..4c554f1
--- /dev/null
+++ b/hostsidetests/securitybulletin/securityPatch/CVE-2019-1988/poc.cpp
@@ -0,0 +1,79 @@
+/*
+ * Copyright (C) 2020 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include "SkAndroidCodec.h"
+#include "SkBitmap.h"
+#include "SkCanvas.h"
+#include "SkData.h"
+#include "SkSurface.h"
+
+#include <fstream>
+#include <iostream>
+#include "../includes/memutils.h"
+
+#define SAMPLE_SIZE 6
+char enable_selective_overload = ENABLE_NONE;
+
+int decode(sk_sp<SkData> bytes, uint8_t sampleSize) {
+    std::unique_ptr < SkAndroidCodec
+            > codec(SkAndroidCodec::NewFromData(bytes));
+    if (!codec) {
+        return EXIT_FAILURE;
+    }
+
+    auto size = codec->getSampledDimensions(sampleSize);
+    auto info = SkImageInfo::MakeN32Premul(size);
+    SkBitmap bm;
+    if (!bm.tryAllocPixels(info)) {
+        return EXIT_FAILURE;
+    }
+
+    SkAndroidCodec::AndroidOptions options;
+    options.fSampleSize = sampleSize;
+
+    codec->getAndroidPixels(bm.info(), bm.getPixels(), bm.rowBytes(), &options);
+    return EXIT_SUCCESS;
+}
+
+int main(int argc, char **argv) {
+    if (argc != 2) {
+        return EXIT_FAILURE;
+    }
+    std::ifstream inFile(argv[1]);
+    if (!inFile) {
+        return EXIT_FAILURE;
+    }
+    inFile.seekg(0, inFile.end);
+    size_t size = inFile.tellg();
+    if (size < 1) {
+        inFile.close();
+        return EXIT_FAILURE;
+    }
+    inFile.seekg(0, inFile.beg);
+    uint8_t *data = (uint8_t *) malloc(size);
+    if (!data) {
+        return EXIT_FAILURE;
+    }
+    inFile.read(reinterpret_cast<char *>(data), size);
+    auto bytes = SkData::MakeWithoutCopy(data, size);
+    bytes = SkData::MakeSubset(bytes.get(), 1, size - 1);
+    enable_selective_overload = ENABLE_ALL;
+    int ret = decode(bytes, SAMPLE_SIZE);
+    enable_selective_overload = ENABLE_NONE;
+    inFile.close();
+    free(data);
+    return ret;
+}
diff --git a/hostsidetests/securitybulletin/src/android/security/cts/TestMedia.java b/hostsidetests/securitybulletin/src/android/security/cts/TestMedia.java
index 72e1e3d..7ce35fc 100644
--- a/hostsidetests/securitybulletin/src/android/security/cts/TestMedia.java
+++ b/hostsidetests/securitybulletin/src/android/security/cts/TestMedia.java
@@ -54,6 +54,18 @@
      ******************************************************************************/
 
     /**
+     * b/118372692
+     * Vulnerability Behaviour: SIGSEGV in self
+     */
+    @Test
+    @SecurityTest(minPatchLevel = "2019-02")
+    public void testPocCVE_2019_1988() throws Exception {
+        String inputFiles[] = {"cve_2019_1988.mp4"};
+        AdbUtils.runPocAssertNoCrashesNotVulnerable("CVE-2019-1988",
+                AdbUtils.TMP_PATH + inputFiles[0], inputFiles, AdbUtils.TMP_PATH, getDevice());
+    }
+
+    /**
      * b/63522430
      * Vulnerability Behaviour: SIGSEGV in media.codec
      */