You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
potential invalid filename/comment buffer access in zipCloseFileInZipRaw*() #295
When creating a new zip entry via zipOpenNewFileInZip*()/zipWriteInFileInZip()/zipCloseFileInZipRaw*() compatibility API trio, the filename pointer passed in zipOpenNewFileInZip*() gets copied to a local structure, that is kept across calls (with the filename pointer in it), and then used again in the close operation. The problem arises when said buffer is no longer there (has different content/has been freed) at the time close is called. In such case, close will access an invalid pointer, calculates strlen() on said pointer and writes that invalid buffer content to the central zip directory. The same is true for the per-file comment pointer.
An explicit requirement to retain buffers between entry creation and close may be a solution, but the original minizip API didn't have such requirement, so the compatible (and also API-user-friendly) solution seems to be making a copy of both filename and comment buffers, and keep those pointers in memory till close is called (and free the buffers on close). This allows the caller to release those buffers right after the zipOpenNewFileInZip*() call, just like with the original minizip lib.
filename/comment can now be NULL if the open operation didn't succeed. API bits will need to made prepared for that. (Or, allocate early, but in such case caller may not call close, so freeing them needs to be done somewhere else.)
make a better effort at releasing these buffers, e.g. along with other freed objects, possibly without the user having to call close at all.
Thank you! mz_stream_write_chars()/mz_stream_write() calls assigns the size written to err, making subsequent instructions fail. After removing those three assignments, the issue is fixed (and much more elegantly so than with my rough patch.)
Activity
vszakats commentedon Aug 14, 2018
Here's a rough patch to fix this (also for the MZ API):
Patch issues:
close, so freeing them needs to be done somewhere else.)closeat all.Fixed potential invalid filename/comment buffer. #295
nmoinvaz commentedon Aug 15, 2018
Alright I made a change. Let me know if that works for you.
vszakats commentedon Aug 15, 2018
Thank you!
mz_stream_write_chars()/mz_stream_write()calls assigns the size written toerr, making subsequent instructions fail. After removing those three assignments, the issue is fixed (and much more elegantly so than with my rough patch.)e.g.:
→
BTW, there is a similar value check issue in this existing call in
mz_zip.c:this should fix it:
Fixed wrong check for writing to stream. #295
nmoinvaz commentedon Aug 15, 2018
I have made the changes. Nice find on the bugs. Thanks for helping make this software better.
vszakats commentedon Aug 15, 2018
You're welcome and no worries! My thanks for your hard work on the revitalised minizip — it's very useful and nicely executed.