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

Bug: 17769851
Bug: 72510314
Test: Ran the new testcase on android-9.0.0_r17 with/without patch

Change-Id: I5ea9619342d9c36088546d17c081e344bfacef0d
diff --git a/hostsidetests/securitybulletin/res/cve_2015_6616.mp4 b/hostsidetests/securitybulletin/res/cve_2015_6616.mp4
new file mode 100644
index 0000000..716c942
--- /dev/null
+++ b/hostsidetests/securitybulletin/res/cve_2015_6616.mp4
Binary files differ
diff --git a/hostsidetests/securitybulletin/securityPatch/CVE-2015-6616/Android.mk b/hostsidetests/securitybulletin/securityPatch/CVE-2015-6616/Android.mk
new file mode 100644
index 0000000..0c69a6d
--- /dev/null
+++ b/hostsidetests/securitybulletin/securityPatch/CVE-2015-6616/Android.mk
@@ -0,0 +1,33 @@
+# Copyright (C) 2019 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-2015-6616
+LOCAL_SRC_FILES := poc.cpp
+LOCAL_MULTILIB := 64
+LOCAL_MODULE_STEM_64 := $(LOCAL_MODULE)64
+LOCAL_C_INCLUDES := frameworks/av/media/libstagefright/include/media/stagefright
+LOCAL_C_INCLUDES += cts/hostsidetests/securitybulletin/securityPatch/includes
+LOCAL_SHARED_LIBRARIES := libstagefright
+LOCAL_SHARED_LIBRARIES += libutils
+
+# 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
+include $(BUILD_CTS_EXECUTABLE)
diff --git a/hostsidetests/securitybulletin/securityPatch/CVE-2015-6616/poc.cpp b/hostsidetests/securitybulletin/securityPatch/CVE-2015-6616/poc.cpp
new file mode 100644
index 0000000..76fad68
--- /dev/null
+++ b/hostsidetests/securitybulletin/securityPatch/CVE-2015-6616/poc.cpp
@@ -0,0 +1,89 @@
+/**
+ * Copyright (C) 2019 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 <dlfcn.h>
+#include <sys/types.h>
+#include <media/DataSource.h>
+#include <media/stagefright/FileSource.h>
+#include <media/MediaExtractor.h>
+#include <media/IMediaExtractor.h>
+#include <media/DataSourceBase.h>
+#include <media/stagefright/MetaData.h>
+#include "common.h"
+#define LIBNAME "/system/lib64/extractors/libmp4extractor.so"
+
+void * operator new(size_t size) {
+    if (size > 64 * 1024 * 1024) {
+        exit (EXIT_VULNERABLE);
+    }
+    return malloc(size);
+}
+
+using namespace android;
+
+int main(int argc, char **argv) {
+    MediaExtractor::GetExtractorDef getDef = nullptr;
+    if (argc < 2) {
+        return EXIT_SUCCESS;
+    }
+
+    void *libHandle = dlopen(LIBNAME, RTLD_NOW | RTLD_LOCAL);
+    if (!libHandle) {
+        return EXIT_SUCCESS;
+    }
+
+    getDef = (MediaExtractor::GetExtractorDef)dlsym(libHandle, "GETEXTRACTORDEF");
+    if (!getDef) {
+        dlclose(libHandle);
+        return EXIT_SUCCESS;
+    }
+
+    sp < DataSource > dataSource = new FileSource(argv[1]);
+    if (dataSource == nullptr) {
+        dlclose(libHandle);
+        return EXIT_SUCCESS;
+    }
+
+    void *meta = nullptr;
+    MediaExtractor::CreatorFunc creator = NULL;
+    MediaExtractor::FreeMetaFunc freeMeta = nullptr;
+    float confidence;
+    creator = getDef().sniff(dataSource.get(), &confidence, &meta, &freeMeta);
+    if (!creator) {
+        dlclose(libHandle);
+        return EXIT_SUCCESS;
+    }
+
+    MediaExtractor *ret = creator(dataSource.get(), meta);
+    if (ret == nullptr) {
+        dlclose(libHandle);
+        return EXIT_SUCCESS;
+    }
+
+    if (meta != nullptr && freeMeta != nullptr) {
+        freeMeta(meta);
+    }
+
+    MediaTrack* source = ret->getTrack(0);
+    if (source == nullptr) {
+        dlclose(libHandle);
+        return EXIT_SUCCESS;
+    }
+
+    source->start(NULL);
+
+    dlclose(libHandle);
+    return EXIT_SUCCESS;
+}
diff --git a/hostsidetests/securitybulletin/src/android/security/cts/TestMedia.java b/hostsidetests/securitybulletin/src/android/security/cts/TestMedia.java
index 5a68d23..5069e15 100644
--- a/hostsidetests/securitybulletin/src/android/security/cts/TestMedia.java
+++ b/hostsidetests/securitybulletin/src/android/security/cts/TestMedia.java
@@ -45,6 +45,17 @@
      ******************************************************************************/
 
     /**
+     * b/17769851
+     * Vulnerability Behaviour: EXIT_VULNERABLE (113)
+     **/
+    @SecurityTest(minPatchLevel = "2015-12")
+    public void testPocCVE_2015_6616() throws Exception {
+        String inputFiles[] = {"cve_2015_6616.mp4"};
+        AdbUtils.runPocAssertNoCrashesNotVulnerable("CVE-2015-6616",
+                AdbUtils.TMP_PATH + inputFiles[0], inputFiles, AdbUtils.TMP_PATH, getDevice());
+    }
+
+    /**
      * b/157650336
      * Vulnerability Behaviour: SIGSEGV in self / EXIT_VULNERABLE (113)
      */