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

Bug: 111603051
Bug: 114102795
Test: Ran the new testcase on android-8.0.0_r11 with/without patch
Change-Id: I225660d857dc31e0c50dde8acb315d0502784360
diff --git a/hostsidetests/securitybulletin/AndroidTest.xml b/hostsidetests/securitybulletin/AndroidTest.xml
index ab54656..bb504fb 100644
--- a/hostsidetests/securitybulletin/AndroidTest.xml
+++ b/hostsidetests/securitybulletin/AndroidTest.xml
@@ -194,6 +194,7 @@
         <!--__________________-->
         <!-- Bulletin 2018-10 -->
         <!-- Please add tests solely from this bulletin below to avoid merge conflict -->
+        <option name="push" value="CVE-2018-9491->/data/local/tmp/CVE-2018-9491" />
         <option name="push" value="CVE-2018-9515->/data/local/tmp/CVE-2018-9515" />
 
         <!--__________________-->
@@ -225,7 +226,6 @@
 
         <!-- Please add 32-bit binary tests below to avoid merge conflict -->
 
-
         <!-- Please add 64-bit binary tests below to avoid merge conflict -->
 
 
diff --git a/hostsidetests/securitybulletin/securityPatch/CVE-2018-9491/Android.bp b/hostsidetests/securitybulletin/securityPatch/CVE-2018-9491/Android.bp
new file mode 100644
index 0000000..5a4e6fa
--- /dev/null
+++ b/hostsidetests/securitybulletin/securityPatch/CVE-2018-9491/Android.bp
@@ -0,0 +1,31 @@
+// 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.
+
+cc_test {
+    name: "CVE-2018-9491",
+    defaults: ["cts_hostsidetests_securitybulletin_defaults"],
+    srcs: [
+        "poc.cpp",
+        ":cts_hostsidetests_securitybulletin_memutils",
+    ],
+    shared_libs: [
+        "libmediandk",
+        "liblog",
+    ],
+    cflags: [
+        "-Wall",
+        "-Werror",
+        "-DCHECK_OVERFLOW",
+    ],
+}
diff --git a/hostsidetests/securitybulletin/securityPatch/CVE-2018-9491/poc.cpp b/hostsidetests/securitybulletin/securityPatch/CVE-2018-9491/poc.cpp
new file mode 100644
index 0000000..09f47b1
--- /dev/null
+++ b/hostsidetests/securitybulletin/securityPatch/CVE-2018-9491/poc.cpp
@@ -0,0 +1,32 @@
+/**
+ * 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 <stdlib.h>
+#include "media/NdkMediaCodec.h"
+#include "../includes/common.h"
+#define NUM_SUB_SAMPLES ((SIZE_MAX / (sizeof(size_t)*2) - 34) + 32)
+
+int main() {
+    uint8_t key[16] = { 1, 2, 3, 4, 1, 2, 3, 4, 1, 2, 3, 4, 1, 2, 3, 4 };
+    uint8_t iv[16] = { 4, 3, 2, 1, 4, 3, 2, 1, 4, 3, 2, 1, 4, 3, 2, 1 };
+    size_t clearBytes[4] = { 5, 6, 7, 8 };
+    size_t encryptedBytes[4] = { 8, 7, 6, 5 };
+
+    AMediaCodecCryptoInfo_new((int) NUM_SUB_SAMPLES, key, iv,
+                              AMEDIACODECRYPTOINFO_MODE_CLEAR, clearBytes,
+                              encryptedBytes);
+
+    return EXIT_SUCCESS;
+}
diff --git a/hostsidetests/securitybulletin/src/android/security/cts/TestMedia.java b/hostsidetests/securitybulletin/src/android/security/cts/TestMedia.java
index 20766ab..5d66a8a 100644
--- a/hostsidetests/securitybulletin/src/android/security/cts/TestMedia.java
+++ b/hostsidetests/securitybulletin/src/android/security/cts/TestMedia.java
@@ -41,6 +41,16 @@
      ******************************************************************************/
 
     /**
+     * b/111603051
+     * Vulnerability Behaviour: SIGSEGV in self
+     */
+    @SecurityTest(minPatchLevel = "2018-10")
+    @Test
+    public void testPocCVE_2018_9491() throws Exception {
+        AdbUtils.runPocAssertNoCrashesNotVulnerable("CVE-2018-9491", null, getDevice());
+    }
+
+    /**
      * b/79662501
      * Vulnerability Behaviour: EXIT_VULNERABLE (113)
      */