summaryrefslogtreecommitdiff
path: root/user/mesa/disk_cache-stack-overflow.patch
blob: 3fad9525989419fc8f19954cd347c7231023dcf5 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
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.

--- mesa-17.3.1/src/util/disk_cache.c.old	2017-12-21 11:31:22.000000000 -0600
+++ mesa-17.3.1/src/util/disk_cache.c	2017-12-29 01:17:15.625633901 -0600
@@ -716,7 +716,7 @@
 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;
@@ -733,6 +733,11 @@
    /* 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;
@@ -754,6 +759,7 @@
          ssize_t written = write_all(dest, out, have);
          if (written == -1) {
             (void)deflateEnd(&strm);
+            free(out);
             return 0;
          }
       } while (strm.avail_out == 0);
@@ -768,6 +774,7 @@
 
    /* clean up and return */
    (void)deflateEnd(&strm);
+   free(out);
    return compressed_size;
 }