summaryrefslogtreecommitdiffhomepage
path: root/src
diff options
context:
space:
mode:
authorRay <[email protected]>2023-09-20 21:23:43 +0200
committerRay <[email protected]>2023-09-20 21:23:43 +0200
commita2b3b1ebe43cdf394b49f901cbaedb2c87959168 (patch)
treea7e39814cc9dd5ffa2864cbb35f492eec524a6e5 /src
parent36e99860ee0c09b87d110f3def6997930d80232e (diff)
downloadraylib-a2b3b1ebe43cdf394b49f901cbaedb2c87959168.tar.gz
raylib-a2b3b1ebe43cdf394b49f901cbaedb2c87959168.zip
REVIEWED: `CompressData()`, possible stack overflow
`struct sdefl` is almost 1MB, in some platforms it could generated a stack overflow, for example WebAssembly, where by default stack is only 65KB!
Diffstat (limited to 'src')
-rw-r--r--src/rcore.c10
1 files changed, 6 insertions, 4 deletions
diff --git a/src/rcore.c b/src/rcore.c
index 0cfaed70..26ff79d9 100644
--- a/src/rcore.c
+++ b/src/rcore.c
@@ -3589,11 +3589,13 @@ unsigned char *CompressData(const unsigned char *data, int dataSize, int *compDa
#if defined(SUPPORT_COMPRESSION_API)
// Compress data and generate a valid DEFLATE stream
- struct sdefl sdefl = { 0 };
- int bounds = sdefl_bound(dataSize);
+ struct sdefl *sdefl = RL_CALLOC(1, sizeof(struct sdefl)); // WARNING: Possible stack overflow, struct sdefl is almost 1MB
+ int bounds = dataSize*2;//sdefl_bound(dataSize);
compData = (unsigned char *)RL_CALLOC(bounds, 1);
- *compDataSize = sdeflate(&sdefl, compData, data, dataSize, COMPRESSION_QUALITY_DEFLATE); // Compression level 8, same as stbiw
-
+
+ *compDataSize = sdeflate(sdefl, compData, data, dataSize, COMPRESSION_QUALITY_DEFLATE); // Compression level 8, same as stbiw
+ RL_FREE(sdefl);
+
TRACELOG(LOG_INFO, "SYSTEM: Compress data: Original size: %i -> Comp. size: %i", dataSize, *compDataSize);
#endif