commit:     60e4a8942f1e6ab43491beab75db633bb53bc857
Author:     Jory Pratt <anarchy <AT> gentoo <DOT> org>
AuthorDate: Tue Jul  2 17:27:36 2019 +0000
Commit:     Jory Pratt <anarchy <AT> gentoo <DOT> org>
CommitDate: Tue Jul  2 17:27:36 2019 +0000
URL:        https://gitweb.gentoo.org/proj/musl.git/commit/?id=60e4a894

media-libs/mesa: Fix stack overflow issues with musl, upstream patch

Package-Manager: Portage-2.3.68, Repoman-2.3.16
Signed-off-by: Jory Pratt <anarchy <AT> gentoo.org>

 .../files/mesa-19.1.0-cache_stack_overflow.patch   | 56 ++++++++++++++++++++++
 .../{mesa-19.1.1.ebuild => mesa-19.1.1-r1.ebuild}  |  1 +
 2 files changed, 57 insertions(+)

diff --git a/media-libs/mesa/files/mesa-19.1.0-cache_stack_overflow.patch 
b/media-libs/mesa/files/mesa-19.1.0-cache_stack_overflow.patch
new file mode 100644
index 0000000..3d6a8df
--- /dev/null
+++ b/media-libs/mesa/files/mesa-19.1.0-cache_stack_overflow.patch
@@ -0,0 +1,56 @@
+From 594d2ec43022871f3b9ad2737e9d7bb97991b2bb Mon Sep 17 00:00:00 2001
+From: Jory Pratt <[email protected]>
+Date: Mon, 17 Jun 2019 09:57:46 -0500
+Subject: [PATCH] The disk cache code tries to allocate a 256 Kbyte buffer on
+ the stack. Since musl only gives 80 Kbyte of stack space per thread, this
+ causes a trap.
+
+Signed-off-by: Jory Pratt <[email protected]>
+---
+ src/util/disk_cache.c | 9 ++++++++-
+ 1 file changed, 8 insertions(+), 1 deletion(-)
+
+diff --git a/src/util/disk_cache.c b/src/util/disk_cache.c
+index 9977c38..c23abdb 100644
+--- a/src/util/disk_cache.c
++++ b/src/util/disk_cache.c
+@@ -732,7 +732,7 @@ static size_t
+ deflate_and_write_to_disk(const void *in_data, size_t in_data_size, int dest,
+                           const char *filename)
+ {
+-   unsigned char out[BUFSIZE];
++   unsigned char *out;
+ 
+    /* allocate deflate state */
+    z_stream strm;
+@@ -749,6 +749,11 @@ deflate_and_write_to_disk(const void *in_data, size_t 
in_data_size, int dest,
+    /* compress until end of in_data */
+    size_t compressed_size = 0;
+    int flush;
++
++   out = calloc(1, BUFSIZE);
++   if (out == NULL)
++      return 0;
++
+    do {
+       int remaining = in_data_size - BUFSIZE;
+       flush = remaining > 0 ? Z_NO_FLUSH : Z_FINISH;
+@@ -770,6 +775,7 @@ deflate_and_write_to_disk(const void *in_data, size_t 
in_data_size, int dest,
+          ssize_t written = write_all(dest, out, have);
+          if (written == -1) {
+             (void)deflateEnd(&strm);
++            free(out);
+             return 0;
+          }
+       } while (strm.avail_out == 0);
+@@ -784,6 +790,7 @@ deflate_and_write_to_disk(const void *in_data, size_t 
in_data_size, int dest,
+ 
+    /* clean up and return */
+    (void)deflateEnd(&strm);
++   free(out);
+    return compressed_size;
+ }
+ 
+-- 
+2.22.0
+

diff --git a/media-libs/mesa/mesa-19.1.1.ebuild 
b/media-libs/mesa/mesa-19.1.1-r1.ebuild
similarity index 99%
rename from media-libs/mesa/mesa-19.1.1.ebuild
rename to media-libs/mesa/mesa-19.1.1-r1.ebuild
index 759f4d0..a7bff8c 100644
--- a/media-libs/mesa/mesa-19.1.1.ebuild
+++ b/media-libs/mesa/mesa-19.1.1-r1.ebuild
@@ -244,6 +244,7 @@ PATCHES=(
        "${FILESDIR}"/${PN}-18-musl-invocation_name.patch
        "${FILESDIR}"/${PN}-18-musl-pthread.patch
        "${FILESDIR}"/${PN}-18.2.4-add-disable-tls-support.patch
+       "${FILESDIR}"/${PN}-19.1.0-cache_stack_overflow.patch
 )
 
 llvm_check_deps() {

Reply via email to