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

Bug: 36576151
Bug: 72456772
Test: Ran the new testcase on android-8.0.0_r30 to test with/without patch

Merged-in: I8bb4a4a05ba40535f99cabdfeabff7564bf2aad9
Change-Id: I8bb4a4a05ba40535f99cabdfeabff7564bf2aad9
diff --git a/hostsidetests/securitybulletin/AndroidTest.xml b/hostsidetests/securitybulletin/AndroidTest.xml
index fe8d23c..7b666be 100644
--- a/hostsidetests/securitybulletin/AndroidTest.xml
+++ b/hostsidetests/securitybulletin/AndroidTest.xml
@@ -142,6 +142,7 @@
         <!--__________________-->
         <!-- Bulletin 2017-07 -->
         <!-- Please add tests solely from this bulletin below to avoid merge conflict -->
+        <option name="push" value="CVE-2017-0678->/data/local/tmp/CVE-2017-0678"/>
         <option name="push" value="CVE-2016-2109->/data/local/tmp/CVE-2016-2109"/>
 
         <!--__________________-->
diff --git a/hostsidetests/securitybulletin/res/cve_2017_0678.mp4 b/hostsidetests/securitybulletin/res/cve_2017_0678.mp4
new file mode 100644
index 0000000..32dd60c
--- /dev/null
+++ b/hostsidetests/securitybulletin/res/cve_2017_0678.mp4
Binary files differ
diff --git a/hostsidetests/securitybulletin/securityPatch/CVE-2017-0678/Android.mk b/hostsidetests/securitybulletin/securityPatch/CVE-2017-0678/Android.mk
new file mode 100644
index 0000000..0c2bd1b
--- /dev/null
+++ b/hostsidetests/securitybulletin/securityPatch/CVE-2017-0678/Android.mk
@@ -0,0 +1,36 @@
+# 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-2017-0678
+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 := frameworks/av/media/libstagefright
+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 -Wno-unused-parameter \
+                  -DCHECK_USE_AFTER_FREE_WITH_WINDOW_SIZE=1048576\
+                  -DCHECK_OVERFLOW -DENABLE_SELECTIVE_OVERLOADING
+include $(BUILD_CTS_EXECUTABLE)
diff --git a/hostsidetests/securitybulletin/securityPatch/CVE-2017-0678/poc.cpp b/hostsidetests/securitybulletin/securityPatch/CVE-2017-0678/poc.cpp
new file mode 100644
index 0000000..30e7299
--- /dev/null
+++ b/hostsidetests/securitybulletin/securityPatch/CVE-2017-0678/poc.cpp
@@ -0,0 +1,46 @@
+/**
+ * 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 <media/stagefright/FileSource.h>
+#include <media/stagefright/MediaExtractor.h>
+#include <media/stagefright/MetaData.h>
+#include "include/MPEG4Extractor.h"
+#include "../includes/memutils.h"
+#define LIBNAME "/system/lib/libstagefright.so"
+
+using namespace android;
+char enable_selective_overload = ENABLE_NONE;
+
+int main(int argc, char **argv) {
+    if (argc < 2) {
+        return EXIT_SUCCESS;
+    }
+    sp < IMediaSource > mediaSource;
+    sp < DataSource > dataSource = new FileSource(argv[1]);
+    MediaExtractor *ret = new MPEG4Extractor(dataSource.get());
+
+    enable_selective_overload = ENABLE_MEMALIGN_CHECK | ENABLE_MALLOC_CHECK
+            | ENABLE_REALLOC_CHECK | ENABLE_FREE_CHECK;
+    size_t numTracks = ret->countTracks();
+    sp < MetaData > metadata;
+    size_t i;
+    for (i = 0; i < numTracks; ++i) {
+        metadata = ret->getTrackMetaData(
+                i, MediaExtractor::kIncludeExtensiveMetaData);
+    }
+    enable_selective_overload = ENABLE_NONE;
+
+    return EXIT_SUCCESS;
+}
diff --git a/hostsidetests/securitybulletin/src/android/security/cts/TestMedia.java b/hostsidetests/securitybulletin/src/android/security/cts/TestMedia.java
index eaa67f0..9552329 100644
--- a/hostsidetests/securitybulletin/src/android/security/cts/TestMedia.java
+++ b/hostsidetests/securitybulletin/src/android/security/cts/TestMedia.java
@@ -49,6 +49,17 @@
      ******************************************************************************/
 
     /**
+     * b/36576151
+     * Vulnerability Behaviour: SIGSEGV in self
+     **/
+    @SecurityTest(minPatchLevel = "2017-07")
+    public void testPocCVE_2017_0678() throws Exception {
+        String inputFiles[] = {"cve_2017_0678.mp4"};
+        AdbUtils.runPocAssertNoCrashesNotVulnerable("CVE-2017-0678",
+                AdbUtils.TMP_PATH + inputFiles[0], inputFiles, AdbUtils.TMP_PATH, getDevice());
+    }
+
+    /**
      *  b/34749571
      *  Vulnerability Behaviour: SIGSEGV in audioserver
      **/