From 6bca273836446d7bd892446605cb0e8c12c6103b Mon Sep 17 00:00:00 2001 From: Elliott Sales de Andrade Date: Sat, 26 Dec 2020 03:27:06 -0500 Subject: [PATCH 1/3] Remove unnecessary executable bit. --- src/miniz.c | 0 1 file changed, 0 insertions(+), 0 deletions(-) mode change 100755 => 100644 src/miniz.c diff --git a/src/miniz.c b/src/miniz.c old mode 100755 new mode 100644 From 937d074adba8561569a91cfec8ff2d21fe255cb5 Mon Sep 17 00:00:00 2001 From: Elliott Sales de Andrade Date: Sat, 26 Dec 2020 04:17:37 -0500 Subject: [PATCH 2/3] Move patched-in functions to the end of the file. --- src/miniz.c | 81 ++++++++++++++++++++++++++--------------------------- 1 file changed, 40 insertions(+), 41 deletions(-) diff --git a/src/miniz.c b/src/miniz.c index 2483416..7e14d6e 100644 --- a/src/miniz.c +++ b/src/miniz.c @@ -3958,47 +3958,6 @@ static MZ_FORCEINLINE const mz_uint8 *mz_zip_get_cdh(mz_zip_archive *pZip, mz_ui return &MZ_ZIP_ARRAY_ELEMENT(&pZip->m_pState->m_central_dir, mz_uint8, MZ_ZIP_ARRAY_ELEMENT(&pZip->m_pState->m_central_dir_offsets, mz_uint32, file_index)); } - -int mz_zip_get_version_made_by(mz_zip_archive *pZip, mz_uint file_index, - mz_uint16 *value) { - mz_uint8 *p = (mz_uint8*) mz_zip_get_cdh(pZip, file_index); - - if (!p) return 0; - - memcpy(value, p + MZ_ZIP_CDH_VERSION_MADE_BY_OFS, sizeof(mz_uint16)); - return 1; -} - -int mz_zip_set_version_made_by(mz_zip_archive *pZip, mz_uint file_index, - mz_uint16 value) { - mz_uint8 *p = (mz_uint8*) mz_zip_get_cdh(pZip, file_index); - - if (!p) return 0; - - memcpy(p + MZ_ZIP_CDH_VERSION_MADE_BY_OFS, &value, sizeof(mz_uint16)); - return 1; -} - -int mz_zip_get_external_attr(mz_zip_archive *pZip, mz_uint file_index, - mz_uint32 *value) { - mz_uint8 *p = (mz_uint8*) mz_zip_get_cdh(pZip, file_index); - - if (!p) return 0; - - memcpy(value, p + MZ_ZIP_CDH_EXTERNAL_ATTR_OFS, sizeof(mz_uint32)); - return 1; -} - -int mz_zip_set_external_attr(mz_zip_archive *pZip, mz_uint file_index, - mz_uint32 value) { - mz_uint8 *p = (mz_uint8*) mz_zip_get_cdh(pZip, file_index); - - if (!p) return 0; - - memcpy(p + MZ_ZIP_CDH_EXTERNAL_ATTR_OFS, &value, sizeof(mz_uint32)); - return 1; -} - mz_bool mz_zip_reader_is_file_encrypted(mz_zip_archive *pZip, mz_uint file_index) { mz_uint m_bit_flag; @@ -7603,6 +7562,46 @@ mz_bool mz_zip_end(mz_zip_archive *pZip) return MZ_FALSE; } +int mz_zip_get_version_made_by(mz_zip_archive *pZip, mz_uint file_index, + mz_uint16 *value) { + mz_uint8 *p = (mz_uint8*) mz_zip_get_cdh(pZip, file_index); + + if (!p) return 0; + + memcpy(value, p + MZ_ZIP_CDH_VERSION_MADE_BY_OFS, sizeof(mz_uint16)); + return 1; +} + +int mz_zip_set_version_made_by(mz_zip_archive *pZip, mz_uint file_index, + mz_uint16 value) { + mz_uint8 *p = (mz_uint8*) mz_zip_get_cdh(pZip, file_index); + + if (!p) return 0; + + memcpy(p + MZ_ZIP_CDH_VERSION_MADE_BY_OFS, &value, sizeof(mz_uint16)); + return 1; +} + +int mz_zip_get_external_attr(mz_zip_archive *pZip, mz_uint file_index, + mz_uint32 *value) { + mz_uint8 *p = (mz_uint8*) mz_zip_get_cdh(pZip, file_index); + + if (!p) return 0; + + memcpy(value, p + MZ_ZIP_CDH_EXTERNAL_ATTR_OFS, sizeof(mz_uint32)); + return 1; +} + +int mz_zip_set_external_attr(mz_zip_archive *pZip, mz_uint file_index, + mz_uint32 value) { + mz_uint8 *p = (mz_uint8*) mz_zip_get_cdh(pZip, file_index); + + if (!p) return 0; + + memcpy(p + MZ_ZIP_CDH_EXTERNAL_ATTR_OFS, &value, sizeof(mz_uint32)); + return 1; +} + #ifdef __cplusplus } #endif From badbf3d84eced18dcd17f18f09c198f44244f3a9 Mon Sep 17 00:00:00 2001 From: Elliott Sales de Andrade Date: Sat, 26 Dec 2020 04:27:10 -0500 Subject: [PATCH 3/3] Use little-endian accessors for central file header. This ensures files are read correctly on big-endian machines. --- src/miniz.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/miniz.c b/src/miniz.c index 7e14d6e..294fee2 100644 --- a/src/miniz.c +++ b/src/miniz.c @@ -7568,7 +7568,7 @@ int mz_zip_get_version_made_by(mz_zip_archive *pZip, mz_uint file_index, if (!p) return 0; - memcpy(value, p + MZ_ZIP_CDH_VERSION_MADE_BY_OFS, sizeof(mz_uint16)); + *value = MZ_READ_LE16(p + MZ_ZIP_CDH_VERSION_MADE_BY_OFS); return 1; } @@ -7578,7 +7578,7 @@ int mz_zip_set_version_made_by(mz_zip_archive *pZip, mz_uint file_index, if (!p) return 0; - memcpy(p + MZ_ZIP_CDH_VERSION_MADE_BY_OFS, &value, sizeof(mz_uint16)); + MZ_WRITE_LE16(p + MZ_ZIP_CDH_VERSION_MADE_BY_OFS, value); return 1; } @@ -7588,7 +7588,7 @@ int mz_zip_get_external_attr(mz_zip_archive *pZip, mz_uint file_index, if (!p) return 0; - memcpy(value, p + MZ_ZIP_CDH_EXTERNAL_ATTR_OFS, sizeof(mz_uint32)); + *value = MZ_READ_LE32(p + MZ_ZIP_CDH_EXTERNAL_ATTR_OFS); return 1; } @@ -7598,7 +7598,7 @@ int mz_zip_set_external_attr(mz_zip_archive *pZip, mz_uint file_index, if (!p) return 0; - memcpy(p + MZ_ZIP_CDH_EXTERNAL_ATTR_OFS, &value, sizeof(mz_uint32)); + MZ_WRITE_LE32(p + MZ_ZIP_CDH_EXTERNAL_ATTR_OFS, value); return 1; }