소스 검색

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!
pull/3350/head
Ray 1 년 전
부모
커밋
a2b3b1ebe4
1개의 변경된 파일6개의 추가작업 그리고 4개의 파일을 삭제
  1. +6
    -4
      src/rcore.c

+ 6
- 4
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 = p">{ 0 };
int bounds = sdefl_bound(dataSize);
struct sdefl o">*sdefl = n">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

불러오는 중...
취소
저장