miniz icon indicating copy to clipboard operation
miniz copied to clipboard

mz_zip_reader_read_central_dir() fails on directory record with different comp & decomp sizes

Open yindian opened this issue 3 years ago • 0 comments

I have encountered some ZIP files containing directory records with 0 compressed size and 4096 decompressed size, which could not be opened using Miniz, due to the following check:

            if ((comp_size != MZ_UINT32_MAX) && (decomp_size != MZ_UINT32_MAX))
            {
                if (((!MZ_READ_LE32(p + MZ_ZIP_CDH_METHOD_OFS)) && (decomp_size != comp_size)) || (decomp_size && !comp_size))
                    return mz_zip_set_error(pZip, MZ_ZIP_INVALID_HEADER_OR_CORRUPTED);
            }

A proposed solution is to check the attribute of the record and ignore the comparison if it is a directory, like this:

            if ((comp_size != MZ_UINT32_MAX) && (decomp_size != MZ_UINT32_MAX)
                && !(MZ_READ_LE32(p + MZ_ZIP_CDH_EXTERNAL_ATTR_OFS) & FILE_ATTRIBUTE_DIRECTORY))
            // ...

yindian avatar Feb 10 '22 08:02 yindian