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

Bug: 32096780
Bug: 72378600
Test: Ran the new testcase on android-8.0.0_r30 with and without patch

Merged-in: I44108877282b43358a5d01fe649ecc3870bedcf6
Change-Id: I44108877282b43358a5d01fe649ecc3870bedcf6
diff --git a/hostsidetests/securitybulletin/AndroidTest.xml b/hostsidetests/securitybulletin/AndroidTest.xml
index 6d71695..72cecce 100644
--- a/hostsidetests/securitybulletin/AndroidTest.xml
+++ b/hostsidetests/securitybulletin/AndroidTest.xml
@@ -150,6 +150,7 @@
         <!--__________________-->
         <!-- Bulletin 2017-08 -->
         <!-- Please add tests solely from this bulletin below to avoid merge conflict -->
+        <option name="push" value="CVE-2017-0713->/data/local/tmp/CVE-2017-0713"/>
 
         <!--__________________-->
         <!-- Bulletin 2017-09 -->
diff --git a/hostsidetests/securitybulletin/res/cve_2017_0713.ttf b/hostsidetests/securitybulletin/res/cve_2017_0713.ttf
new file mode 100644
index 0000000..1f316ef
--- /dev/null
+++ b/hostsidetests/securitybulletin/res/cve_2017_0713.ttf
Binary files differ
diff --git a/hostsidetests/securitybulletin/securityPatch/CVE-2017-0713/Android.mk b/hostsidetests/securitybulletin/securityPatch/CVE-2017-0713/Android.mk
new file mode 100644
index 0000000..c14f89c
--- /dev/null
+++ b/hostsidetests/securitybulletin/securityPatch/CVE-2017-0713/Android.mk
@@ -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.
+
+LOCAL_PATH := $(call my-dir)
+include $(CLEAR_VARS)
+
+LOCAL_MODULE := CVE-2017-0713
+LOCAL_SRC_FILES := poc.cpp
+LOCAL_MULTILIB := both
+LOCAL_MODULE_STEM_32 := $(LOCAL_MODULE)32
+LOCAL_MODULE_STEM_64 := $(LOCAL_MODULE)64
+LOCAL_C_INCLUDES := external/skia/include/core
+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
+include $(BUILD_CTS_EXECUTABLE)
diff --git a/hostsidetests/securitybulletin/securityPatch/CVE-2017-0713/poc.cpp b/hostsidetests/securitybulletin/securityPatch/CVE-2017-0713/poc.cpp
new file mode 100644
index 0000000..5d8b3cb
--- /dev/null
+++ b/hostsidetests/securitybulletin/securityPatch/CVE-2017-0713/poc.cpp
@@ -0,0 +1,81 @@
+/**
+ * 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 <sys/stat.h>
+#include <fcntl.h>
+#include <unistd.h>
+#include <stdio.h>
+#include <sys/mman.h>
+#include "SkDocument.h"
+#include "SkStream.h"
+#include "SkTypeface.h"
+#include "SkCanvas.h"
+
+#define ALLOC_SIZE  191422
+void* g_mmap_ptr = NULL;
+
+void * operator new(size_t size) {
+    if (size != ALLOC_SIZE) {
+        return malloc(size);
+    }
+    void* mem_ptr = mmap(NULL, size, PROT_READ | PROT_WRITE,
+                         MAP_FILE | MAP_SHARED | MAP_ANONYMOUS, -1, 0);
+    if (mem_ptr == MAP_FAILED) {
+        return malloc(size);
+    }
+    g_mmap_ptr = mem_ptr;
+    return mem_ptr;
+}
+
+void operator delete(void* mem_ptr) {
+    if(g_mmap_ptr == mem_ptr) {
+        munmap(mem_ptr, ALLOC_SIZE);
+        return;
+    }
+    return free(mem_ptr);
+}
+
+struct NullWStream : public SkWStream {
+    NullWStream()
+            : fN(0) {
+    }
+    bool write(const void*, size_t n) override {
+        fN += n;
+        return true;
+    }
+    size_t bytesWritten() const override {
+        return fN;
+    }
+    size_t fN;
+};
+
+int main(int argc, char **argv) {
+    if (argc != 2) {
+        return EXIT_SUCCESS;
+    }
+    SkWStream* outputStream = new NullWStream();
+    SkScalar pageWidth = 100;
+    SkScalar pageHeight = 100;
+    SkPaint paint;
+    char text[] = "C";
+    sk_sp < SkDocument > pdfDocument(SkDocument::MakePDF(outputStream));
+    SkCanvas* pageCanvas = pdfDocument->beginPage(pageWidth, pageHeight);
+    sk_sp < SkTypeface > typeFace = SkTypeface::MakeFromFile(argv[1]);
+    paint.setTypeface(typeFace);
+    pageCanvas->drawText(text, strlen(text), 0, 0, paint);
+    pdfDocument->endPage();
+    pdfDocument->close();
+    return EXIT_SUCCESS;
+}
diff --git a/hostsidetests/securitybulletin/src/android/security/cts/TestMedia.java b/hostsidetests/securitybulletin/src/android/security/cts/TestMedia.java
index 58699ce..9321116 100644
--- a/hostsidetests/securitybulletin/src/android/security/cts/TestMedia.java
+++ b/hostsidetests/securitybulletin/src/android/security/cts/TestMedia.java
@@ -49,6 +49,17 @@
      ******************************************************************************/
 
     /**
+     * b/32096780
+     * Vulnerability Behaviour: SIGSEGV in self
+     **/
+    @SecurityTest(minPatchLevel = "2017-08")
+    public void testPocCVE_2017_0713() throws Exception {
+        String inputFiles[] = {"cve_2017_0713.ttf"};
+        AdbUtils.runPocAssertNoCrashesNotVulnerable("CVE-2017-0713",
+                AdbUtils.TMP_PATH + inputFiles[0], inputFiles, AdbUtils.TMP_PATH, getDevice());
+    }
+
+    /**
      * b/112159345
      * Vulnerability Behaviour: SIGSEGV in self
      **/