Mesa (master): util: Heap-allocate 256K zlib buffer
GitLab Mirror
gitlab-mirror at kemper.freedesktop.org
Wed Jun 19 19:30:33 UTC 2019
Module: Mesa
Branch: master
Commit: fd7b7f14d857f96cf3b2e9d8405dbbfa30dc261a
URL: http://cgit.freedesktop.org/mesa/mesa/commit/?id=fd7b7f14d857f96cf3b2e9d8405dbbfa30dc261a
Author: Jory Pratt <anarchy at gentoo.org>
Date: Mon Jun 10 11:48:02 2019 -0700
util: Heap-allocate 256K zlib buffer
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.
See https://wiki.musl-libc.org/functional-differences-from-glibc.html#Thread-stack-size
(In musl-1.1.21 the default stack size has increased to 128K)
[mattst88]: Original author unknown, but I think this is small enough
that it is not copyrightable.
Reviewed-by: Matt Turner <mattst88 at gmail.com>
Reviewed-by: Eric Anholt <eric at anholt.net>
Reviewed-by: Eric Engestrom <eric.engestrom at intel.com>
---
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 9977c385de1..bc3becfe535 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 = malloc(BUFSIZE * sizeof(unsigned char));
+ 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;
}
More information about the mesa-commit
mailing list