Closed JsHuang closed 5 years ago
Thanks for reporting this.
As per issue #25, this is not a security issue. It's up to code controlling libmspack to set hard memory usage limits, if such limits are desired. Use a custom mspack_system.alloc()
function to return NULL
to libmspack if it goes over your arbitrary memory limit, instead of allocating the memory. libmspack will follow through and return MSPACK_ERR_NOMEMORY
to the client.
However, I agree with adding another validation here, to reject bad CHM files. chmhs1_ChunkSize
commonly only ever has one value, 4096. All files created with hhc.exe
have this value. I have a single file with a larger chunk size (8192) and it was created by someone developing a competing CHM file creator, which they've since abandoned.
I've set an upper limit of 8192 for this field in commit 3b106e2a284bafde0448a14b8a4bf37747bbac4b.
If anyone has valid CHM files where this field is larger, please write to me.
Description:
function chmd_read_headers() in libmspack has a memory exhausted problem
Affected version:
libmspack 0.9.1 alpha
Details:
Critical code(in chmd.c):
In function
chmd_read_headers()
in file chmd.c,chm->chunk_size
was read from chm file and lately allocate memory of sizechm->chunk_size
, without check whetherchm->chunk_size
is valid, Carefully constructed chm file will lead to memory exhausted problem.
chm->chunk_size
is 32bit, it can be as large as0xffffffff
. The maximum memory usage ofchmd_read_headers()
can be 4G RAM, even if the input file is very small.poc file
https://github.com/JsHuang/pocs/blob/master/libmspack/oom-chm
Credit: ADLab of Venustech