mirror of
				https://github.com/raysan5/raylib.git
				synced 2025-11-04 09:44:20 +00:00 
			
		
		
		
	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!
This commit is contained in:
		@@ -3589,10 +3589,12 @@ unsigned char *CompressData(const unsigned char *data, int dataSize, int *compDa
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
#if defined(SUPPORT_COMPRESSION_API)
 | 
					#if defined(SUPPORT_COMPRESSION_API)
 | 
				
			||||||
    // Compress data and generate a valid DEFLATE stream
 | 
					    // Compress data and generate a valid DEFLATE stream
 | 
				
			||||||
    struct sdefl sdefl = { 0 };
 | 
					    struct sdefl *sdefl = RL_CALLOC(1, sizeof(struct sdefl));   // WARNING: Possible stack overflow, struct sdefl is almost 1MB
 | 
				
			||||||
    int bounds = sdefl_bound(dataSize);
 | 
					    int bounds = dataSize*2;//sdefl_bound(dataSize);
 | 
				
			||||||
    compData = (unsigned char *)RL_CALLOC(bounds, 1);
 | 
					    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);
 | 
					    TRACELOG(LOG_INFO, "SYSTEM: Compress data: Original size: %i -> Comp. size: %i", dataSize, *compDataSize);
 | 
				
			||||||
#endif
 | 
					#endif
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user