barnson / miniz

Automatically exported from code.google.com/p/miniz
1 stars 1 forks source link

Miniz fails to locate file in ZIP archive #15

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
Summary: The function mz_zip_extract_archive_file_to_heap() can fail to locate 
an archive member, because it uses binary search in the central directory, even 
if that central directory was never sorted because the   
MZ_ZIP_FLAG_DO_NOT_SORT_CENTRAL_DIRECTORY flag was specified when initializing 
the archive reader.

The problem is caused by the following two lines in mz_zip_reader_locate_file():

 if (((flags & (MZ_ZIP_FLAG_IGNORE_PATH | MZ_ZIP_FLAG_CASE_SENSITIVE) == 0) && (!pComment) && (pZip->m_pState->m_sorted_central_dir_offsets.m_p))
    return mz_zip_reader_locate_file_binary_search(pZip, pName);

The check whether pZip->m_pState->m_sorted_central_dir_offsets.m_p is 
initialized is probably meant to determine whether the central directory was 
sorted.  However, the pZip->m_pState->m_sorted_central_dir_offsets array is 
*always* initialized, irrespective of whether the central directory was sorted 
or not (see the definition of  mz_zip_reader_read_central_dir()).

Hence, a different way of checking whether the central directory has been 
sorted should be implemented.

Original issue reported on code.google.com by jeremy.j...@gmail.com on 9 Sep 2013 at 1:45

GoogleCodeExporter commented 9 years ago
Thanks for finding this Jeremy.

Original comment by richge...@gmail.com on 9 Sep 2013 at 7:42

GoogleCodeExporter commented 9 years ago
My pleasure. And thanks for this great library.

Jeremy

Original comment by jeremy.j...@gmail.com on 9 Sep 2013 at 8:38

GoogleCodeExporter commented 9 years ago
This should be fixed in v1.15.

Original comment by richge...@gmail.com on 13 Oct 2013 at 5:27