8000 minizip/unzip.c at 1.2 · rogerou/minizip · GitHub
[go: up one dir, main page]

Skip to content

Latest commit

 

History

History
1980 lines (1681 loc) · 70.8 KB

unzip.c

File metadata and controls

1980 lines (1681 loc) · 70.8 KB
if (unzReadUInt16(&s->z_filefunc, s->filestream_with_CD, &value16) != UNZ_OK)
err = UNZ_ERRNO;
/* Support AE-1 and AE-2 */
if (value16 != 1 && value16 != 2)
err = UNZ_ERRNO;
file_info_internal.aes_version = value16;
if (unzReadUInt8(&s->z_filefunc, s->filestream_with_CD, &value8) != UNZ_OK)
err = UNZ_ERRNO;
if ((char)value8 != 'A')
err = UNZ_ERRNO;
if (unzReadUInt8(&s->z_filefunc, s->filestream_with_CD, &value8) != UNZ_OK)
err = UNZ_ERRNO;
if ((char)value8 != 'E')
err = UNZ_ERRNO;
/* Get AES encryption strength and actual compression method */
if (unzReadUInt8(&s->z_filefunc, s->filestream_with_CD, &value8) != UNZ_OK)
err = UNZ_ERRNO;
file_info_internal.aes_encryption_mode = value8;
if (unzReadUInt16(&s->z_filefunc, s->filestream_with_CD, &value16) != UNZ_OK)
err = UNZ_ERRNO;
file_info_internal.aes_compression_method = value16;
}
#endif
else
{
if (ZSEEK64(s->z_filefunc, s->filestream_with_CD,extra_data_size, ZLIB_FILEFUNC_SEEK_CUR) != 0)
err = UNZ_ERRNO;
}
extra_pos += 2 + 2 + extra_data_size;
}
}
if (file_info.disk_num_start == s->gi.number_disk_with_CD)
file_info_internal.byte_before_the_zipfile = s->byte_before_the_zipfile;
else
file_info_internal.byte_before_the_zipfile = 0;
if (err == UNZ_OK)
err = unzGetCurrentFileInfoField(file, &seek, comment, comment_size, file_info.size_file_comment, 1);
if ((err == UNZ_OK) && (pfile_info != NULL))
*pfile_info = file_info;
if ((err == UNZ_OK) && (pfile_info_internal != NULL))
*pfile_info_internal = file_info_internal;
return err;
}
extern int ZEXPORT unzGetCurrentFileInfo(unzFile file, unz_file_info *pfile_info, char *filename,
uint16_t filename_size, void *extrafield, uint16_t extrafield_size, char *comment, uint16_t comment_size)
{
unz_file_info64 file_info64;
int err = UNZ_OK;
err = unzGetCurrentFileInfoInternal(file, &file_info64, NULL, filename, filename_size,
extrafield, extrafield_size, comment, comment_size);
if ((err == UNZ_OK) && (pfile_info != NULL))
{
pfile_info->version = file_info64.version;
pfile_info->version_needed = file_info64.version_needed;
pfile_info->flag = file_info64.flag;
pfile_info->compression_method = file_info64.compression_method;
pfile_info->dos_date = file_info64.dos_date;
pfile_info->crc = file_info64.crc;
pfile_info->size_filename = file_info64.size_filename;
pfile_info->size_file_extra = file_info64.size_file_extra - file_info64.size_file_extra_internal;
pfile_info->size_file_comment = file_info64.size_file_comment;
pfile_info->disk_num_start = (uint16_t)file_info64.disk_num_start;
pfile_info->internal_fa = file_info64.internal_fa;
pfile_info->external_fa = file_info64.external_fa;
pfile_info->compressed_size = (uint32_t)file_info64.compressed_size;
pfile_info->uncompressed_size = (uint32_t)file_info64.uncompressed_size;
}
return err;
}
extern int ZEXPORT unzGetCurrentFileInfo64(unzFile file, unz_file_info64 * pfile_info, char *filename,
uint16_t filename_size, void *extrafield, uint16_t extrafield_size, char *comment, uint16_t comment_size)
{
return unzGetCurrentFileInfoInternal(file, pfile_info, NULL, filename, filename_size,
extrafield, extrafield_size, comment,comment_size);
}
/* Read the local header of the current zipfile. Check the coherency of the local header and info in the
end of central directory about this file store in *piSizeVar the size of extra info in local header
(filename and size of extra field data) */
static int unzCheckCurrentFileCoherencyHeader(unz64_internal *s, uint32_t *psize_variable, uint64_t *poffset_local_extrafield,
uint16_t *psize_local_extrafield)
{
uint32_t magic = 0;
uint16_t value16 = 0;
uint32_t value32 = 0;
uint32_t flags = 0;
uint16_t size_filename = 0;
uint16_t size_extra_field = 0;
uint16_t compression_method = 0;
int err = UNZ_OK;
if (psize_variable == NULL)
return UNZ_PARAMERROR;
*psize_variable = 0;
if (poffset_local_extrafield == NULL)
return UNZ_PARAMERROR;
*poffset_local_extrafield = 0;
if (psize_local_extrafield == NULL)
return UNZ_PARAMERROR;
*psize_local_extrafield = 0;
err = unzGoToNextDisk((unzFile)s);
if (err != UNZ_OK)
return err;
if (ZSEEK64(s->z_filefunc, s->filestream, s->cur_file_info_internal.offset_curfile +
s->cur_file_info_internal.byte_before_the_zipfile, ZLIB_FILEFUNC_SEEK_SET) != 0)
return UNZ_ERRNO;
if (err == UNZ_OK)
{
if (unzReadUInt32(&s->z_filefunc, s->filestream, &magic) != UNZ_OK)
err = UNZ_ERRNO;
else if (magic != LOCALHEADERMAGIC)
err = UNZ_BADZIPFILE;
}
if (unzReadUInt16(&s->z_filefunc, s->filestream, &value16) != UNZ_OK)
err = UNZ_ERRNO;
if (unzReadUInt16(&s->z_filefunc, s->filestream, &value16) != UNZ_OK)
err = UNZ_ERRNO;
flags = value16;
if (unzReadUInt16(&s->z_filefunc, s->filestream, &value16) != UNZ_OK)
err = UNZ_ERRNO;
else if ((err == UNZ_OK) && (value16 != s->cur_file_info.compression_method))
err = UNZ_BADZIPFILE;
compression_method = s->cur_file_info.compression_method;
#ifdef HAVE_AES
if (compression_method == AES_METHOD)
compression_method = s->cur_file_info_internal.aes_compression_method;
#endif
if ((err == UNZ_OK) && (compression_method != 0) && (compression_method != Z_DEFLATED))
{
#ifdef HAVE_BZIP2
if (compression_method != Z_BZIP2ED)
#endif
err = UNZ_BADZIPFILE;
}
if (unzReadUInt32(&s->z_filefunc, s->filestream, &value32) != UNZ_OK) /* date/time */
0