From 8410f3c640ad0c0e667af174cccf8ec5de026e9d Mon Sep 17 00:00:00 2001 From: ariel shtul Date: Sun, 1 Nov 2020 12:02:06 +0200 Subject: [PATCH 1/5] remove redundant condition L#1067 asserts that (match_len >= TDEFL_MIN_MATCH_LEN) --- miniz_tdef.c | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/miniz_tdef.c b/miniz_tdef.c index 64113f8..e42fc6e 100644 --- a/miniz_tdef.c +++ b/miniz_tdef.c @@ -1074,9 +1074,7 @@ static MZ_FORCEINLINE void tdefl_record_match(tdefl_compressor *d, mz_uint match s0 = s_tdefl_small_dist_sym[match_dist & 511]; s1 = s_tdefl_large_dist_sym[(match_dist >> 8) & 127]; d->m_huff_count[1][(match_dist < 512) ? s0 : s1]++; - - if (match_len >= TDEFL_MIN_MATCH_LEN) - d->m_huff_count[0][s_tdefl_len_sym[match_len - TDEFL_MIN_MATCH_LEN]]++; + d->m_huff_count[0][s_tdefl_len_sym[match_len - TDEFL_MIN_MATCH_LEN]]++; } static mz_bool tdefl_compress_normal(tdefl_compressor *d) From b7f04b700bfedc447f5f048a534513341d8d7cca Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=92=D0=BB=D0=B0=D0=B4=D0=B8=D1=81=D0=BB=D0=B0=D0=B2=20?= =?UTF-8?q?=D0=A9=D0=B0=D0=BF=D0=BE=D0=B2?= Date: Fri, 26 Feb 2021 20:08:39 +0500 Subject: [PATCH 2/5] Improved cmake subproject support - Added code to determine whether this is a standalone project or included by other projects. - Added option INSTALL_PROJECT to enable/disable install project. - Replaced CMAKE_BINARY_DIR to CMAKE_CURRENT_BINARY_DIR. --- CMakeLists.txt | 110 ++++++++++++++++++++++++++++--------------------- 1 file changed, 62 insertions(+), 48 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 9b4873e..c9f5827 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -7,7 +7,11 @@ else() project(miniz C) endif() -include(GNUInstallDirs) +# determine whether this is a standalone project or included by other projects +set(MINIZ_STANDALONE_PROJECT OFF) +if (CMAKE_CURRENT_SOURCE_DIR STREQUAL CMAKE_SOURCE_DIR) + set(MINIZ_STANDALONE_PROJECT ON) +endif () set(MINIZ_API_VERSION 2) set(MINIZ_MINOR_VERSION 1) @@ -23,14 +27,19 @@ if(CMAKE_BUILD_TYPE STREQUAL "") CMAKE_C_FLAGS used) Debug Release RelWithDebInfo MinSizeRel." FORCE) endif () -option(BUILD_EXAMPLES "Build examples" ON) +option(BUILD_EXAMPLES "Build examples" ${MINIZ_STANDALONE_PROJECT}) option(BUILD_FUZZERS "Build fuzz targets" OFF) option(AMALGAMATE_SOURCES "Amalgamate sources into miniz.h/c" OFF) option(BUILD_HEADER_ONLY "Build a header-only version" OFF) option(BUILD_SHARED_LIBS "Build shared library instead of static" ON) +option(INSTALL_PROJECT "Install project" ${MINIZ_STANDALONE_PROJECT}) set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/bin) +if(INSTALL_PROJECT) + include(GNUInstallDirs) +endif() + if(BUILD_HEADER_ONLY) set(AMALGAMATE_SOURCES ON CACHE BOOL "Build a header-only version" FORCE) endif(BUILD_HEADER_ONLY) @@ -124,11 +133,13 @@ if(NOT BUILD_HEADER_ONLY) PRIVATE $<$:_GNU_SOURCE>) # pkg-config file - configure_file(miniz.pc.in ${CMAKE_BINARY_DIR}/miniz.pc @ONLY) + configure_file(miniz.pc.in ${CMAKE_CURRENT_BINARY_DIR}/miniz.pc @ONLY) - install(FILES - ${CMAKE_BINARY_DIR}/miniz.pc - DESTINATION ${CMAKE_INSTALL_DATADIR}/pkgconfig) + if(INSTALL_PROJECT) + install(FILES + ${CMAKE_CURRENT_BINARY_DIR}/miniz.pc + DESTINATION ${CMAKE_INSTALL_DATADIR}/pkgconfig) + endif() endif() set_property(TARGET ${PROJECT_NAME} PROPERTY @@ -137,48 +148,50 @@ set_property(TARGET ${PROJECT_NAME} APPEND PROPERTY COMPATIBLE_INTERFACE_STRING ${PROJECT_NAME}_MAJOR_VERSION ) -install(TARGETS ${PROJECT_NAME} EXPORT ${PROJECT_NAME}Targets - RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR} - ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR} - LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} - # users can use or - INCLUDES DESTINATION include ${CMAKE_INSTALL_INCLUDEDIR}/${PROJECT_NAME} -) +if(INSTALL_PROJECT) + install(TARGETS ${PROJECT_NAME} EXPORT ${PROJECT_NAME}Targets + RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR} + ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR} + LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} + # users can use or + INCLUDES DESTINATION include ${CMAKE_INSTALL_INCLUDEDIR}/${PROJECT_NAME} + ) -include(CMakePackageConfigHelpers) -write_basic_package_version_file( - "${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}/${PROJECT_NAME}ConfigVersion.cmake" - VERSION ${MINIZ_VERSION} - COMPATIBILITY AnyNewerVersion -) - -export(EXPORT ${PROJECT_NAME}Targets - FILE "${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}/${PROJECT_NAME}Targets.cmake" - NAMESPACE ${PROJECT_NAME}:: -) -configure_file(Config.cmake.in - "${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}/${PROJECT_NAME}Config.cmake" - @ONLY -) - -set(ConfigPackageLocation ${CMAKE_INSTALL_LIBDIR}/cmake/${PROJECT_NAME}) -install(EXPORT ${PROJECT_NAME}Targets - FILE - ${PROJECT_NAME}Targets.cmake - NAMESPACE - ${PROJECT_NAME}:: - DESTINATION - ${ConfigPackageLocation} -) -install( - FILES - "${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}/${PROJECT_NAME}Config.cmake" + include(CMakePackageConfigHelpers) + write_basic_package_version_file( "${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}/${PROJECT_NAME}ConfigVersion.cmake" - DESTINATION - ${ConfigPackageLocation} - COMPONENT - Devel -) + VERSION ${MINIZ_VERSION} + COMPATIBILITY AnyNewerVersion + ) + + export(EXPORT ${PROJECT_NAME}Targets + FILE "${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}/${PROJECT_NAME}Targets.cmake" + NAMESPACE ${PROJECT_NAME}:: + ) + configure_file(Config.cmake.in + "${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}/${PROJECT_NAME}Config.cmake" + @ONLY + ) + + set(ConfigPackageLocation ${CMAKE_INSTALL_LIBDIR}/cmake/${PROJECT_NAME}) + install(EXPORT ${PROJECT_NAME}Targets + FILE + ${PROJECT_NAME}Targets.cmake + NAMESPACE + ${PROJECT_NAME}:: + DESTINATION + ${ConfigPackageLocation} + ) + install( + FILES + "${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}/${PROJECT_NAME}Config.cmake" + "${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}/${PROJECT_NAME}ConfigVersion.cmake" + DESTINATION + ${ConfigPackageLocation} + COMPONENT + Devel + ) +endif() if(BUILD_EXAMPLES) set(EXAMPLE1_SRC_LIST "${CMAKE_CURRENT_SOURCE_DIR}/examples/example1.c") @@ -250,6 +263,7 @@ endif() set(INCLUDE_INSTALL_DIR "include") -install(FILES ${INSTALL_HEADERS} DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/${PROJECT_NAME}) - +if(INSTALL_PROJECT) + install(FILES ${INSTALL_HEADERS} DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/${PROJECT_NAME}) +endif() From 57176046b57ba2002d9c2fde5fb2065e209a5d95 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vojt=C4=9Bch=20=C5=A0amla?= Date: Wed, 19 May 2021 10:37:15 +0200 Subject: [PATCH 3/5] Make cmake recognize FetchContent subproject --- CMakeLists.txt | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index c9f5827..1cb713a 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,5 +1,11 @@ cmake_minimum_required(VERSION 3.0) +# determine whether this is a standalone project or included by other projects +set (MINIZ_STANDALONE_PROJECT ON) +if(DEFINED PROJECT_NAME) + set(MINIZ_STANDALONE_PROJECT OFF) +endif() + if(CMAKE_MINOR_VERSION LESS 12) project(miniz) # see issue https://gitlab.kitware.com/cmake/cmake/merge_requests/1799 @@ -7,12 +13,6 @@ else() project(miniz C) endif() -# determine whether this is a standalone project or included by other projects -set(MINIZ_STANDALONE_PROJECT OFF) -if (CMAKE_CURRENT_SOURCE_DIR STREQUAL CMAKE_SOURCE_DIR) - set(MINIZ_STANDALONE_PROJECT ON) -endif () - set(MINIZ_API_VERSION 2) set(MINIZ_MINOR_VERSION 1) set(MINIZ_PATCH_VERSION 0) From cf2833fdc137f6388138067c62fdf29d6cbf18b6 Mon Sep 17 00:00:00 2001 From: Andre Maroneze Date: Tue, 25 May 2021 15:23:35 +0200 Subject: [PATCH 4/5] avoid use of uninitialized value in tdefl_record_literal In tdefl_record_literal, the following expression may read an uninitialized value in the m_pLZ_flags field: *d->m_pLZ_flags = (mz_uint8)(*d->m_pLZ_flags >> 1); By explicitly initializing it, we avoid possible undefined behaviors. Issue found with Frama-C. --- miniz_tdef.c | 1 + 1 file changed, 1 insertion(+) diff --git a/miniz_tdef.c b/miniz_tdef.c index 64113f8..4eb8e07 100644 --- a/miniz_tdef.c +++ b/miniz_tdef.c @@ -1333,6 +1333,7 @@ tdefl_status tdefl_init(tdefl_compressor *d, tdefl_put_buf_func_ptr pPut_buf_fun d->m_output_flush_ofs = d->m_output_flush_remaining = d->m_finished = d->m_block_index = d->m_bit_buffer = d->m_wants_to_finish = 0; d->m_pLZ_code_buf = d->m_lz_code_buf + 1; d->m_pLZ_flags = d->m_lz_code_buf; + *d->m_pLZ_flags = 0; d->m_num_flags_left = 8; d->m_pOutput_buf = d->m_output_buf; d->m_pOutput_buf_end = d->m_output_buf; From 58254a324168b6142cc87ccb3ca258f5284153f1 Mon Sep 17 00:00:00 2001 From: Andreas Deininger Date: Wed, 2 Jun 2021 22:48:50 +0200 Subject: [PATCH 5/5] readme.md: fix broken links ChangeLog.md: fix typo --- ChangeLog.md | 2 +- readme.md | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/ChangeLog.md b/ChangeLog.md index 3ee292d..13cbd18 100644 --- a/ChangeLog.md +++ b/ChangeLog.md @@ -82,7 +82,7 @@ The inflator now has a new failure status TINFL_STATUS_FAILED_CANNOT_MAKE_PROGRE - The inflator coroutine func. is subtle and complex so I'm being cautious about this release. I would greatly appreciate any help with testing or any feedback. I feel good about these changes, and they've been through several hours of automated testing, but they will probably not fix anything for the majority of prev. users so I'm going to mark this release as beta for a few weeks and continue testing it at work/home on various things. -- The inflator in raw (non-zlib) mode is now usable on gzip or similiar data streams that have a bunch of bytes following the raw deflate data (problem discovered by rustyzip author williamw520). +- The inflator in raw (non-zlib) mode is now usable on gzip or similar data streams that have a bunch of bytes following the raw deflate data (problem discovered by rustyzip author williamw520). This version should *never* read beyond the last byte of the raw deflate data independent of how many bytes you pass into the input buffer. This issue was caused by the various Huffman bitbuffer lookahead optimizations, and would not be an issue if the caller knew and enforced the precise size of the raw compressed data *or* if the compressed data was in zlib format (i.e. always followed by the byte aligned zlib adler32). So in other words, you can now call the inflator on deflate streams that are followed by arbitrary amounts of data and it's guaranteed that decompression will stop exactly on the last byte. diff --git a/readme.md b/readme.md index 127d16f..3f8fd73 100644 --- a/readme.md +++ b/readme.md @@ -31,4 +31,4 @@ Thanks to Bruce Dawson for reporting a problem with the level_and_flags archive ## Patents -I was recently asked if miniz avoids patent issues. miniz purposely uses the same core algorithms as the ones used by zlib. The compressor uses vanilla hash chaining as described [here](http://www.gzip.org/zlib/rfc-deflate.html#algorithm). Also see the [gzip FAQ](http://www.gzip.org/#faq11). In my opinion, if miniz falls prey to a patent attack then zlib/gzip are likely to be at serious risk too. +I was recently asked if miniz avoids patent issues. miniz purposely uses the same core algorithms as the ones used by zlib. The compressor uses vanilla hash chaining as described [here](https://datatracker.ietf.org/doc/html/rfc1951#section-4). Also see the [gzip FAQ](https://web.archive.org/web/20160308045258/http://www.gzip.org/#faq11). In my opinion, if miniz falls prey to a patent attack then zlib/gzip are likely to be at serious risk too.