@@ -2562,19 +2562,20 @@ unsigned char *DecompressData(const unsigned char *compData, int compDataSize, i
25622562
25632563#if defined(SUPPORT_COMPRESSION_API )
25642564 // Decompress data from a valid DEFLATE stream
2565- data = (unsigned char * )RL_CALLOC (MAX_DECOMPRESSION_SIZE * 1024 * 1024 , 1 );
2565+ unsigned char * data0 = (unsigned char * )RL_CALLOC (MAX_DECOMPRESSION_SIZE * 1024 * 1024 , 1 );
25662566 int length = sinflate (data , MAX_DECOMPRESSION_SIZE * 1024 * 1024 , compData , compDataSize );
25672567
2568- // WARNING: RL_REALLOC can make (and leave) data copies in memory, be careful with sensitive compressed data!
2569- // TODO: Use a different approach, create another buffer, copy data manually to it and wipe original buffer memory
2570- unsigned char * temp = (unsigned char * )RL_REALLOC (data , length );
2571-
2572- if (temp != NULL ) data = temp ;
2573- else TRACELOG (LOG_WARNING , "SYSTEM: Failed to re-allocate required decompression memory" );
2568+ // WARNING: RL_REALLOC can make (and leave) data copies in memory,
2569+ // that can be a security concern in case of compression of sensitive data
2570+ // So, we use a second buffer to copy data manually, wiping original buffer memory
2571+ data = (unsigned char * )RL_CALLOC (length , 1 );
2572+ memcpy (data , data0 , length );
2573+ memset (data0 , 0 , MAX_DECOMPRESSION_SIZE * 1024 * 1024 ); // Wipe memory, is memset() safe?
2574+ RL_FREE (data0 );
2575+
2576+ TRACELOG (LOG_INFO , "SYSTEM: Decompress data: Comp. size: %i -> Original size: %i" , compDataSize , length );
25742577
25752578 * dataSize = length ;
2576-
2577- TRACELOG (LOG_INFO , "SYSTEM: Decompress data: Comp. size: %i -> Original size: %i" , compDataSize , * dataSize );
25782579#endif
25792580
25802581 return data ;
0 commit comments