mirror of
				https://github.com/eledio-devices/thirdparty-miniz.git
				synced 2025-10-31 16:14:16 +01:00 
			
		
		
		
	Compare commits
	
		
			123 Commits
		
	
	
		
	
	| Author | SHA1 | Date | |
|---|---|---|---|
|  | cb97387d20 | ||
|  | d301afc498 | ||
|  | 8ac52a6cae | ||
|  | 2281a42c77 | ||
|  | 17b4f33dde | ||
|  | f2df122f6f | ||
|  | 6e1754595a | ||
|  | 0c905aec41 | ||
|  | ee598099cb | ||
|  | 61b202f26a | ||
|  | a145b53b6a | ||
|  | 58254a3241 | ||
|  | cf2833fdc1 | ||
|  | 57176046b5 | ||
|  | 9edb278d22 | ||
|  | b7f04b700b | ||
|  | 75744d32d4 | ||
|  | b43f8a0c22 | ||
|  | 17d6763721 | ||
|  | 31b389ac61 | ||
|  | fe03be2c51 | ||
|  | 60bbf6c808 | ||
|  | b99e5c3de3 | ||
|  | d6566206ce | ||
|  | 6241bc718c | ||
|  | 6b6b27aff2 | ||
|  | 3a43b8c4bb | ||
|  | 864ecc8d14 | ||
|  | f52e09a208 | ||
|  | 95795bb996 | ||
|  | 0bac8947c5 | ||
|  | 90ff5d51e4 | ||
|  | fe4a8b78f3 | ||
|  | 225354290d | ||
|  | b485d01faf | ||
|  | 1cdb9afad0 | ||
|  | cd65995953 | ||
|  | 1721df91bb | ||
|  | d1640e7c4f | ||
|  | 9457abb670 | ||
|  | 8410f3c640 | ||
|  | 209ba6540c | ||
|  | 1e7621d96c | ||
|  | 5ebed82882 | ||
|  | e6faac9881 | ||
|  | 65ad3cdf66 | ||
|  | 320764e3ca | ||
|  | d34ae4a14f | ||
|  | aa3c99a7b4 | ||
|  | f33da29f61 | ||
|  | b36e55e48d | ||
|  | 797c58be3c | ||
|  | d2d7d090fa | ||
|  | 436d915546 | ||
|  | 164c81c7d7 | ||
|  | a8e9424b16 | ||
|  | fa09b1f3d4 | ||
|  | 4159f8c8c3 | ||
|  | ccff20b76d | ||
|  | 1e8c7ce810 | ||
|  | e48d8bab88 | ||
|  | a828cc329c | ||
|  | 1567c8d06c | ||
|  | a88d1571c1 | ||
|  | f66b3e1901 | ||
|  | 5108f95f58 | ||
|  | 3a00ea8b73 | ||
|  | a0dd5179db | ||
|  | 107def8e36 | ||
|  | 334e0d64ce | ||
|  | 0238ce2a3b | ||
|  | cd99affed0 | ||
|  | bee490c712 | ||
|  | 6ed35304fe | ||
|  | e0c964c4a3 | ||
|  | 416f5ea723 | ||
|  | e8ab1c9a6d | ||
|  | e71344bdd7 | ||
|  | 3b9a004a4f | ||
|  | d57872c77a | ||
|  | b713ca2b4a | ||
|  | 185bc3c683 | ||
|  | ff06fbaafc | ||
|  | 1261dfa9ad | ||
|  | ea41268ac9 | ||
|  | c3e5de6699 | ||
|  | a3aeeb3307 | ||
|  | 4ec19d6731 | ||
|  | a4264837ae | ||
|  | b4936524bc | ||
|  | e9020723b3 | ||
|  | 5ba89c135d | ||
|  | 25de35faec | ||
|  | 4d1d5b6771 | ||
|  | 034f0228eb | ||
|  | 4b8c4f432c | ||
|  | 9d79ea2245 | ||
|  | 6db3c0d290 | ||
|  | 96f0da1db9 | ||
|  | 93c6567773 | ||
|  | 2b45f89867 | ||
|  | 5c62e23e04 | ||
|  | f3461d636a | ||
|  | 45a080c050 | ||
|  | 2e15a3ff77 | ||
|  | d31e119d4d | ||
|  | 3a884afaa7 | ||
|  | ae423e65b4 | ||
|  | 336fca3bd4 | ||
|  | a3ca94f833 | ||
|  | 9ce0d0ddff | ||
|  | f8600923fc | ||
|  | 306edd2022 | ||
|  | 407d298c14 | ||
|  | 53bfef515c | ||
|  | 91fa285a27 | ||
|  | df65d5a1de | ||
|  | 46cdde2ac5 | ||
|  | 3616bf804b | ||
|  | 76237898c0 | ||
|  | 3af5c82fd3 | ||
|  | 55f4dfe1d2 | ||
|  | b344eaf775 | 
							
								
								
									
										17
									
								
								.github/workflows/c-cpp.yml
									
									
									
									
										vendored
									
									
										Normal file
									
								
							
							
						
						
									
										17
									
								
								.github/workflows/c-cpp.yml
									
									
									
									
										vendored
									
									
										Normal file
									
								
							| @@ -0,0 +1,17 @@ | ||||
| name: C/C++ CI | ||||
|  | ||||
| on: | ||||
|   push: | ||||
|     branches: [ master ] | ||||
|   pull_request: | ||||
|     branches: [ master ] | ||||
|  | ||||
| jobs: | ||||
|   build: | ||||
|  | ||||
|     runs-on: ubuntu-latest | ||||
|  | ||||
|     steps: | ||||
|     - uses: actions/checkout@v2 | ||||
|     - name: amalgamate | ||||
|       run: bash amalgamate.sh | ||||
							
								
								
									
										23
									
								
								.github/workflows/ci-fuzz.yml
									
									
									
									
										vendored
									
									
										Normal file
									
								
							
							
						
						
									
										23
									
								
								.github/workflows/ci-fuzz.yml
									
									
									
									
										vendored
									
									
										Normal file
									
								
							| @@ -0,0 +1,23 @@ | ||||
| name: CIFuzz | ||||
| on: [pull_request] | ||||
| jobs: | ||||
|   Fuzzing: | ||||
|     runs-on: ubuntu-latest | ||||
|     steps: | ||||
|     - name: Build Fuzzers | ||||
|       uses: google/oss-fuzz/infra/cifuzz/actions/build_fuzzers@master | ||||
|       with: | ||||
|         oss-fuzz-project-name: 'miniz' | ||||
|         dry-run: false | ||||
|     - name: Run Fuzzers | ||||
|       uses: google/oss-fuzz/infra/cifuzz/actions/run_fuzzers@master | ||||
|       with: | ||||
|         oss-fuzz-project-name: 'miniz' | ||||
|         fuzz-seconds: 900 | ||||
|         dry-run: false | ||||
|     - name: Upload Crash | ||||
|       uses: actions/upload-artifact@v1 | ||||
|       if: failure() | ||||
|       with: | ||||
|         name: artifacts | ||||
|         path: ./out/artifacts | ||||
							
								
								
									
										60
									
								
								.github/workflows/release.yml
									
									
									
									
										vendored
									
									
										Normal file
									
								
							
							
						
						
									
										60
									
								
								.github/workflows/release.yml
									
									
									
									
										vendored
									
									
										Normal file
									
								
							| @@ -0,0 +1,60 @@ | ||||
| name: Create release | ||||
|  | ||||
| # Controls when the action will run.  | ||||
| on: | ||||
|   # Allows you to run this workflow manually from the Actions tab | ||||
|   workflow_dispatch: | ||||
|  | ||||
| jobs: | ||||
|   build: | ||||
|     name: Create new release | ||||
|     runs-on: ubuntu-latest | ||||
|      | ||||
|     steps: | ||||
|       # Checks-out your repository under $GITHUB_WORKSPACE, so your job can access it | ||||
|       - name: Checkout code | ||||
|         uses: actions/checkout@v2 | ||||
|         with: | ||||
|           path: source | ||||
|          | ||||
|       - name: Install dependencies | ||||
|         run: | | ||||
|           sudo apt-get install -y cmake | ||||
|            | ||||
|       - name: Configure | ||||
|         run: | | ||||
|           mkdir build | ||||
|           mkdir inst | ||||
|           cd build | ||||
|           cmake ../source -G"Unix Makefiles" -DAMALGAMATE_SOURCES=ON -DCMAKE_INSTALL_PREFIX=../inst | ||||
|            | ||||
|       - name: Build | ||||
|         run: | | ||||
|           cd build | ||||
|           make install | ||||
|          | ||||
|       - name: Get current version | ||||
|         id: relver | ||||
|         run: echo "::set-output name=relver::$(cat build/miniz.pc | grep Version | cut -d ':' -f2 | xargs)" | ||||
|          | ||||
|       - name: Create Release | ||||
|         id: create_release | ||||
|         uses: actions/create-release@v1 | ||||
|         env: | ||||
|           GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | ||||
|         with: | ||||
|           tag_name: ${{ steps.relver.outputs.relver }} | ||||
|           release_name: Release ${{ steps.relver.outputs.relver }} | ||||
|           draft: false | ||||
|           prerelease: false | ||||
|            | ||||
|       - name: Upload Release Asset | ||||
|         id: upload-release-asset  | ||||
|         uses: actions/upload-release-asset@v1 | ||||
|         env: | ||||
|           GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | ||||
|         with: | ||||
|           upload_url: ${{ steps.create_release.outputs.upload_url }} | ||||
|           asset_path: ./build/miniz-${{ steps.relver.outputs.relver }}.zip | ||||
|           asset_name: miniz-${{ steps.relver.outputs.relver }}.zip | ||||
|           asset_content_type: application/zip | ||||
							
								
								
									
										318
									
								
								CMakeLists.txt
									
									
									
									
									
								
							
							
						
						
									
										318
									
								
								CMakeLists.txt
									
									
									
									
									
								
							| @@ -1,5 +1,24 @@ | ||||
| PROJECT(miniz C) | ||||
| cmake_minimum_required(VERSION 2.8) | ||||
| 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 | ||||
| else() | ||||
|   project(miniz C) | ||||
| endif() | ||||
|  | ||||
| set(MINIZ_API_VERSION 2) | ||||
| set(MINIZ_MINOR_VERSION 2) | ||||
| set(MINIZ_PATCH_VERSION 0) | ||||
| set(MINIZ_VERSION  | ||||
|     ${MINIZ_API_VERSION}.${MINIZ_MINOR_VERSION}.${MINIZ_PATCH_VERSION}) | ||||
|  | ||||
| if(CMAKE_BUILD_TYPE STREQUAL "") | ||||
|   # CMake defaults to leaving CMAKE_BUILD_TYPE empty. This screws up | ||||
|   # differentiation between debug and release builds. | ||||
| @@ -8,45 +27,268 @@ if(CMAKE_BUILD_TYPE STREQUAL "") | ||||
| CMAKE_C_FLAGS used) Debug Release RelWithDebInfo MinSizeRel." FORCE) | ||||
| endif () | ||||
|  | ||||
| set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_SOURCE_DIR}/bin) | ||||
| 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(miniz_SOURCE miniz.c miniz_zip.c miniz_tinfl.c miniz_tdef.c) | ||||
| set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/bin) | ||||
|  | ||||
| add_library(miniz ${miniz_SOURCE}) | ||||
|  | ||||
| set(EXAMPLE1_SRC_LIST "${CMAKE_CURRENT_SOURCE_DIR}/examples/example1.c") | ||||
| set(EXAMPLE2_SRC_LIST "${CMAKE_CURRENT_SOURCE_DIR}/examples/example2.c") | ||||
| set(EXAMPLE3_SRC_LIST "${CMAKE_CURRENT_SOURCE_DIR}/examples/example3.c") | ||||
| set(EXAMPLE4_SRC_LIST "${CMAKE_CURRENT_SOURCE_DIR}/examples/example4.c") | ||||
| set(EXAMPLE5_SRC_LIST "${CMAKE_CURRENT_SOURCE_DIR}/examples/example5.c") | ||||
| set(EXAMPLE6_SRC_LIST "${CMAKE_CURRENT_SOURCE_DIR}/examples/example6.c") | ||||
| set(MINIZ_TESTER_SRC_LIST | ||||
|     "${CMAKE_CURRENT_SOURCE_DIR}/tests/miniz_tester.cpp" | ||||
|     "${CMAKE_CURRENT_SOURCE_DIR}/tests/timer.cpp") | ||||
|  | ||||
| include_directories(${CMAKE_CURRENT_SOURCE_DIR}) | ||||
| add_executable(example1 ${EXAMPLE1_SRC_LIST}) | ||||
| target_link_libraries(example1 miniz) | ||||
| add_executable(example2 ${EXAMPLE2_SRC_LIST}) | ||||
| target_link_libraries(example2 miniz) | ||||
| add_executable(example3 ${EXAMPLE3_SRC_LIST}) | ||||
| target_link_libraries(example3 miniz) | ||||
| add_executable(example4 ${EXAMPLE4_SRC_LIST}) | ||||
| target_link_libraries(example4 miniz) | ||||
| add_executable(example5 ${EXAMPLE5_SRC_LIST}) | ||||
| target_link_libraries(example5 miniz) | ||||
| add_executable(example6 ${EXAMPLE6_SRC_LIST}) | ||||
| target_link_libraries(example6 miniz) | ||||
| if(${UNIX}) | ||||
|     target_link_libraries(example6 m) | ||||
| if(INSTALL_PROJECT) | ||||
|   include(GNUInstallDirs) | ||||
| endif() | ||||
|  | ||||
| # add_executable(miniz_tester ${MINIZ_TESTER_SRC_LIST}) | ||||
| # target_link_libraries(miniz_tester miniz) | ||||
| if(BUILD_HEADER_ONLY) | ||||
|   set(AMALGAMATE_SOURCES ON CACHE BOOL "Build a header-only version" FORCE) | ||||
| endif(BUILD_HEADER_ONLY) | ||||
|  | ||||
| install(TARGETS ${PROJECT_NAME} EXPORT ${PROJECT_NAME}Targets | ||||
|     ARCHIVE  DESTINATION lib | ||||
|     LIBRARY DESTINATION lib | ||||
| if(AMALGAMATE_SOURCES) | ||||
|   # Amalgamate | ||||
|   file(COPY miniz.h DESTINATION ${CMAKE_CURRENT_BINARY_DIR}/amalgamation/) | ||||
|   file(READ miniz.h MINIZ_H) | ||||
|   file(READ miniz_common.h MINIZ_COMMON_H) | ||||
|   file(READ miniz_tdef.h MINIZ_TDEF_H) | ||||
|   file(READ miniz_tinfl.h MINIZ_TINFL_H) | ||||
|   file(READ miniz_zip.h MINIZ_ZIP_H) | ||||
|   file(APPEND ${CMAKE_CURRENT_BINARY_DIR}/amalgamation/miniz.h | ||||
|      "${MINIZ_COMMON_H} ${MINIZ_TDEF_H} ${MINIZ_TINFL_H} ${MINIZ_ZIP_H}") | ||||
|  | ||||
|   file(COPY miniz.c DESTINATION ${CMAKE_CURRENT_BINARY_DIR}/amalgamation/) | ||||
|   file(READ miniz_tdef.c MINIZ_TDEF_C) | ||||
|   file(READ miniz_tinfl.c MINIZ_TINFL_C) | ||||
|   file(READ miniz_zip.c MINIZ_ZIP_C) | ||||
|   file(APPEND ${CMAKE_CURRENT_BINARY_DIR}/amalgamation/miniz.c | ||||
|      "${MINIZ_TDEF_C} ${MINIZ_TINFL_C} ${MINIZ_ZIP_C}") | ||||
|  | ||||
|   file(READ ${CMAKE_CURRENT_BINARY_DIR}/amalgamation/miniz.h AMAL_MINIZ_H) | ||||
|   file(READ ${CMAKE_CURRENT_BINARY_DIR}/amalgamation/miniz.c AMAL_MINIZ_C) | ||||
|   foreach(REPLACE_STRING miniz;miniz_common;miniz_tdef;miniz_tinfl;miniz_zip;miniz_export) | ||||
|     string(REPLACE "#include \"${REPLACE_STRING}.h\"" "" AMAL_MINIZ_H "${AMAL_MINIZ_H}") | ||||
|     string(REPLACE "#include \"${REPLACE_STRING}.h\"" "" AMAL_MINIZ_C "${AMAL_MINIZ_C}") | ||||
|   endforeach() | ||||
|   string(CONCAT AMAL_MINIZ_H "#define MINIZ_EXPORT\n" "${AMAL_MINIZ_H}") | ||||
|   if(BUILD_HEADER_ONLY) | ||||
|     string(CONCAT AMAL_MINIZ_H "${AMAL_MINIZ_H}" "\n#ifndef MINIZ_HEADER_FILE_ONLY\n" | ||||
|              "${AMAL_MINIZ_C}" "\n#endif // MINIZ_HEADER_FILE_ONLY\n") | ||||
|     file(WRITE ${CMAKE_CURRENT_BINARY_DIR}/amalgamation/miniz.h "${AMAL_MINIZ_H}") | ||||
|     add_library(${PROJECT_NAME} INTERFACE) | ||||
|      | ||||
|     # Might not be a good idea to force this on the library user | ||||
|     # as it could bloat the global namespace | ||||
|     # https://github.com/libevent/libevent/issues/460 | ||||
|     # target_compile_definitions(${PROJECT_NAME}  | ||||
|     #     INTERFACE $<$<C_COMPILER_ID:GNU>:_GNU_SOURCE>) | ||||
|      | ||||
|     set_property(TARGET ${PROJECT_NAME} APPEND  | ||||
|       PROPERTY INTERFACE_INCLUDE_DIRECTORIES | ||||
|       $<BUILD_INTERFACE:${CMAKE_CURRENT_BINARY_DIR}/amalgamation> | ||||
|       $<INSTALL_INTERFACE:include> | ||||
|     ) | ||||
| file(GLOB INSTALL_HEADERS ${CMAKE_CURRENT_SOURCE_DIR}/*.h) | ||||
| install(FILES ${INSTALL_HEADERS} DESTINATION include/${PROJECT_NAME}) | ||||
|   else(BUILD_HEADER_ONLY) | ||||
|     string(CONCAT AMAL_MINIZ_C "#include \"miniz.h\"\n" "${AMAL_MINIZ_C}") | ||||
|     file(WRITE ${CMAKE_CURRENT_BINARY_DIR}/amalgamation/miniz.h "${AMAL_MINIZ_H}") | ||||
|     file(WRITE ${CMAKE_CURRENT_BINARY_DIR}/amalgamation/miniz.c "${AMAL_MINIZ_C}") | ||||
|     set(miniz_SOURCE ${CMAKE_CURRENT_BINARY_DIR}/amalgamation/miniz.h | ||||
|                      ${CMAKE_CURRENT_BINARY_DIR}/amalgamation/miniz.c) | ||||
|     add_library(${PROJECT_NAME} STATIC ${miniz_SOURCE}) | ||||
|     target_include_directories(${PROJECT_NAME} PUBLIC | ||||
|       $<BUILD_INTERFACE:${CMAKE_CURRENT_BINARY_DIR}/amalgamation> | ||||
|       $<INSTALL_INTERFACE:include> | ||||
|     ) | ||||
|   endif(BUILD_HEADER_ONLY) | ||||
|  | ||||
|   set(INSTALL_HEADERS ${CMAKE_CURRENT_BINARY_DIR}/amalgamation/miniz.h) | ||||
|    | ||||
|   file(GLOB_RECURSE ZIP_FILES RELATIVE "${CMAKE_CURRENT_BINARY_DIR}/amalgamation" "${CMAKE_CURRENT_BINARY_DIR}/amalgamation/*") | ||||
|   file(GLOB_RECURSE ZIP_FILES2 RELATIVE "${CMAKE_SOURCE_DIR}" "${CMAKE_SOURCE_DIR}/examples/*") | ||||
|   list(APPEND ZIP_FILES ${ZIP_FILES2}) | ||||
|   list(APPEND ZIP_FILES "ChangeLog.md") | ||||
|   list(APPEND ZIP_FILES "readme.md") | ||||
|   list(APPEND ZIP_FILES "LICENSE") | ||||
|   set(ZIP_OUT_FN "${CMAKE_CURRENT_BINARY_DIR}/miniz-${MINIZ_VERSION}.zip") | ||||
|   message(STATUS "Zip files: ${ZIP_FILES}") | ||||
|   add_custom_command( | ||||
| 		COMMAND ${CMAKE_COMMAND} -E copy_directory ${CMAKE_SOURCE_DIR}/examples ${CMAKE_CURRENT_BINARY_DIR}/amalgamation/examples | ||||
| 		COMMAND ${CMAKE_COMMAND} -E copy ${CMAKE_SOURCE_DIR}/ChangeLog.md ${CMAKE_CURRENT_BINARY_DIR}/amalgamation/ChangeLog.md | ||||
| 		COMMAND ${CMAKE_COMMAND} -E copy ${CMAKE_SOURCE_DIR}/readme.md ${CMAKE_CURRENT_BINARY_DIR}/amalgamation/readme.md | ||||
| 		COMMAND ${CMAKE_COMMAND} -E copy ${CMAKE_SOURCE_DIR}/LICENSE ${CMAKE_CURRENT_BINARY_DIR}/amalgamation/LICENSE | ||||
| 		COMMAND ${CMAKE_COMMAND} -E tar "cf" "${ZIP_OUT_FN}" --format=zip -- ${ZIP_FILES} | ||||
|         WORKING_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/amalgamation" | ||||
|         OUTPUT  "${ZIP_OUT_FN}" | ||||
|         DEPENDS ${ZIP_FILES} | ||||
|         COMMENT "Zipping to ${CMAKE_CURRENT_BINARY_DIR}/miniz.zip." | ||||
|     ) | ||||
| 	 | ||||
| 	add_custom_target( | ||||
| 	  create_zip ALL | ||||
| 	  DEPENDS "${ZIP_OUT_FN}" | ||||
| 	) | ||||
| else(AMALGAMATE_SOURCES) | ||||
|   include(GenerateExportHeader) | ||||
|   set(miniz_SOURCE miniz.c miniz_zip.c miniz_tinfl.c miniz_tdef.c) | ||||
|   add_library(${PROJECT_NAME} ${miniz_SOURCE}) | ||||
|   generate_export_header(${PROJECT_NAME}) | ||||
|  | ||||
|   if(NOT BUILD_SHARED_LIBS) | ||||
|     string(TOUPPER ${PROJECT_NAME} PROJECT_UPPER) | ||||
|     set_target_properties(${PROJECT_NAME} | ||||
|         PROPERTIES INTERFACE_COMPILE_DEFINITIONS ${PROJECT_UPPER}_STATIC_DEFINE) | ||||
|   else() | ||||
|     set_property(TARGET ${PROJECT_NAME} PROPERTY C_VISIBILITY_PRESET hidden) | ||||
|   endif() | ||||
|  | ||||
|   set_property(TARGET ${PROJECT_NAME} PROPERTY VERSION ${MINIZ_VERSION}) | ||||
|   set_property(TARGET ${PROJECT_NAME} PROPERTY SOVERSION ${MINIZ_API_VERSION}) | ||||
|    | ||||
|   target_include_directories(${PROJECT_NAME} PUBLIC | ||||
|     $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}> | ||||
|     $<BUILD_INTERFACE:${CMAKE_CURRENT_BINARY_DIR}> | ||||
|     $<INSTALL_INTERFACE:include> | ||||
|   ) | ||||
|    | ||||
|   file(GLOB INSTALL_HEADERS ${CMAKE_CURRENT_SOURCE_DIR}/*.h) | ||||
|   list(APPEND | ||||
|        INSTALL_HEADERS ${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}_export.h) | ||||
| endif(AMALGAMATE_SOURCES) | ||||
|  | ||||
| if(NOT BUILD_HEADER_ONLY) | ||||
|   target_compile_definitions(${PROJECT_NAME}  | ||||
|     PRIVATE $<$<C_COMPILER_ID:GNU>:_GNU_SOURCE>) | ||||
|  | ||||
|   # pkg-config file | ||||
|   configure_file(miniz.pc.in ${CMAKE_CURRENT_BINARY_DIR}/miniz.pc @ONLY) | ||||
|  | ||||
|   if(INSTALL_PROJECT) | ||||
|     install(FILES | ||||
|       ${CMAKE_CURRENT_BINARY_DIR}/miniz.pc | ||||
|       DESTINATION ${CMAKE_INSTALL_DATADIR}/pkgconfig) | ||||
|   endif() | ||||
| endif() | ||||
|  | ||||
| set_property(TARGET ${PROJECT_NAME} PROPERTY | ||||
|   INTERFACE_${PROJECT_NAME}_MAJOR_VERSION ${MINIZ_API_VERSION}) | ||||
| set_property(TARGET ${PROJECT_NAME} APPEND PROPERTY | ||||
|   COMPATIBLE_INTERFACE_STRING ${PROJECT_NAME}_MAJOR_VERSION | ||||
| ) | ||||
|  | ||||
| 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 <miniz.h> or <miniz/miniz.h> | ||||
|     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" | ||||
|       "${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") | ||||
|   set(EXAMPLE2_SRC_LIST "${CMAKE_CURRENT_SOURCE_DIR}/examples/example2.c") | ||||
|   set(EXAMPLE3_SRC_LIST "${CMAKE_CURRENT_SOURCE_DIR}/examples/example3.c") | ||||
|   set(EXAMPLE4_SRC_LIST "${CMAKE_CURRENT_SOURCE_DIR}/examples/example4.c") | ||||
|   set(EXAMPLE5_SRC_LIST "${CMAKE_CURRENT_SOURCE_DIR}/examples/example5.c") | ||||
|   set(EXAMPLE6_SRC_LIST "${CMAKE_CURRENT_SOURCE_DIR}/examples/example6.c") | ||||
|   set(MINIZ_TESTER_SRC_LIST | ||||
|       "${CMAKE_CURRENT_SOURCE_DIR}/tests/miniz_tester.cpp" | ||||
|       "${CMAKE_CURRENT_SOURCE_DIR}/tests/timer.cpp") | ||||
|  | ||||
|   add_executable(example1 ${EXAMPLE1_SRC_LIST}) | ||||
|   target_link_libraries(example1 miniz) | ||||
|   add_executable(example2 ${EXAMPLE2_SRC_LIST}) | ||||
|   target_link_libraries(example2 miniz) | ||||
|   add_executable(example3 ${EXAMPLE3_SRC_LIST}) | ||||
|   target_link_libraries(example3 miniz) | ||||
|   add_executable(example4 ${EXAMPLE4_SRC_LIST}) | ||||
|   target_link_libraries(example4 miniz) | ||||
|   add_executable(example5 ${EXAMPLE5_SRC_LIST}) | ||||
|   target_link_libraries(example5 miniz) | ||||
|   add_executable(example6 ${EXAMPLE6_SRC_LIST}) | ||||
|   target_link_libraries(example6 miniz) | ||||
|   if(${UNIX}) | ||||
|       target_link_libraries(example6 m) | ||||
|   endif() | ||||
|  | ||||
|   # add_executable(miniz_tester ${MINIZ_TESTER_SRC_LIST}) | ||||
|   # target_link_libraries(miniz_tester miniz) | ||||
| endif(BUILD_EXAMPLES) | ||||
|  | ||||
| if(BUILD_FUZZERS) | ||||
|   set(FUZZ_MAIN_SRC "${CMAKE_CURRENT_SOURCE_DIR}/tests/fuzz_main.c") | ||||
|  | ||||
|   set(CHECKSUM_FUZZER_SRC_LIST "${FUZZ_MAIN_SRC}" "${CMAKE_CURRENT_SOURCE_DIR}/tests/checksum_fuzzer.c") | ||||
|   set(FLUSH_FUZZER_SRC_LIST "${FUZZ_MAIN_SRC}" "${CMAKE_CURRENT_SOURCE_DIR}/tests/flush_fuzzer.c") | ||||
|   set(UNCOMPRESS_FUZZER_SRC_LIST "${FUZZ_MAIN_SRC}" "${CMAKE_CURRENT_SOURCE_DIR}/tests/uncompress_fuzzer.c") | ||||
|   set(UNCOMPRESS2_FUZZER_SRC_LIST "${FUZZ_MAIN_SRC}" "${CMAKE_CURRENT_SOURCE_DIR}/tests/uncompress2_fuzzer.c") | ||||
|   set(COMPRESS_FUZZER_SRC_LIST "${FUZZ_MAIN_SRC}" "${CMAKE_CURRENT_SOURCE_DIR}/tests/compress_fuzzer.c") | ||||
|   set(SMALL_FUZZER_SRC_LIST "${FUZZ_MAIN_SRC}" "${CMAKE_CURRENT_SOURCE_DIR}/tests/small_fuzzer.c") | ||||
|   set(LARGE_FUZZER_SRC_LIST "${FUZZ_MAIN_SRC}" "${CMAKE_CURRENT_SOURCE_DIR}/tests/large_fuzzer.c") | ||||
|   set(ZIP_FUZZER_SRC_LIST "${FUZZ_MAIN_SRC}" "${CMAKE_CURRENT_SOURCE_DIR}/tests/zip_fuzzer.c") | ||||
|  | ||||
|   add_executable(checksum_fuzzer ${CHECKSUM_FUZZER_SRC_LIST}) | ||||
|   target_link_libraries(checksum_fuzzer miniz) | ||||
|  | ||||
|   add_executable(flush_fuzzer ${FLUSH_FUZZER_SRC_LIST}) | ||||
|   target_link_libraries(flush_fuzzer miniz) | ||||
|  | ||||
|   add_executable(uncompress_fuzzer ${UNCOMPRESS_FUZZER_SRC_LIST}) | ||||
|   target_link_libraries(uncompress_fuzzer miniz) | ||||
|  | ||||
|   add_executable(uncompress2_fuzzer ${UNCOMPRESS2_FUZZER_SRC_LIST}) | ||||
|   target_link_libraries(uncompress2_fuzzer miniz) | ||||
|  | ||||
|   add_executable(compress_fuzzer ${COMPRESS_FUZZER_SRC_LIST}) | ||||
|   target_link_libraries(compress_fuzzer miniz) | ||||
|  | ||||
|   add_executable(small_fuzzer ${SMALL_FUZZER_SRC_LIST}) | ||||
|   target_link_libraries(small_fuzzer miniz) | ||||
|  | ||||
|   add_executable(large_fuzzer ${LARGE_FUZZER_SRC_LIST}) | ||||
|   target_link_libraries(large_fuzzer miniz) | ||||
|  | ||||
|   add_executable(zip_fuzzer ${ZIP_FUZZER_SRC_LIST}) | ||||
|   target_link_libraries(zip_fuzzer miniz) | ||||
| endif() | ||||
|  | ||||
| set(INCLUDE_INSTALL_DIR "include") | ||||
|  | ||||
| if(INSTALL_PROJECT) | ||||
|   install(FILES ${INSTALL_HEADERS} DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/${PROJECT_NAME}) | ||||
| endif() | ||||
|  | ||||
|   | ||||
							
								
								
									
										72
									
								
								ChangeLog.md
									
									
									
									
									
								
							
							
						
						
									
										72
									
								
								ChangeLog.md
									
									
									
									
									
								
							| @@ -1,5 +1,70 @@ | ||||
| ## Changelog | ||||
|  | ||||
| ### 2.2.0 | ||||
|  | ||||
|  - Fix examples with amalgamation | ||||
|  - Modified cmake script to support shared library mode and find_package | ||||
|  - Fix for misleading doc comment on `mz_zip_reader_init_cfile` function | ||||
|  - Add include location tolerance and stop forcing `_GNU_SOURCE` | ||||
|  - Fix: mz_zip_reader_locate_file_v2 returns an mz_bool | ||||
|  - Fix large file system checks | ||||
|  - Add #elif to enable an external mz_crc32() to be linked in | ||||
|  - Write with dynamic size (size of file/data to be added not known before adding) | ||||
|  - Added uncompress2 for zlib compatibility | ||||
|  - Add support for building as a Meson subproject | ||||
|  - Added OSSFuzz support; Integrate with CIFuzz | ||||
|  - Add pkg-config file | ||||
|  - Fixed use-of-uninitialized value msan error when copying dist bytes with no output bytes written. | ||||
|  - mz_zip_validate_file(): fix memory leak on errors | ||||
|  - Fixed MSAN use-of-uninitialized in tinfl_decompress when invalid dist is decoded. In this instance dist was 31 which s_dist_base translates as 0 | ||||
|  - Add flag to set (compressed) size in local file header | ||||
|  - avoid use of uninitialized value in tdefl_record_literal | ||||
|  | ||||
| ### 2.1.0 | ||||
|  | ||||
|  - More instances of memcpy instead of cast and use memcpy per default | ||||
|  - Remove inline for c90 support | ||||
|  - New function to read files via callback functions when adding them | ||||
|  - Fix out of bounds read while reading Zip64 extended information | ||||
|  - guard memcpy when n == 0 because buffer may be NULL | ||||
|  - Implement inflateReset() function | ||||
|  - Move comp/decomp alloc/free  prototypes under guarding #ifndef MZ_NO_MALLOC | ||||
|  - Fix large file support under Windows | ||||
|  - Don't warn if _LARGEFILE64_SOURCE is not defined to 1 | ||||
|  - Fixes for MSVC warnings | ||||
|  - Remove check that path of file added to archive contains ':' or '\' | ||||
|  - Add !defined check on MINIZ_USE_ALIGNED_LOADS_AND_STORES | ||||
|  | ||||
| ### 2.0.8 | ||||
|  | ||||
|  - Remove unimplemented functions (mz_zip_locate_file and mz_zip_locate_file_v2) | ||||
|  - Add license, changelog, readme and example files to release zip | ||||
|  - Fix heap overflow to user buffer in tinfl_status tinfl_decompress | ||||
|  - Fix corrupt archive if uncompressed file smaller than 4 byte and the file is added by mz_zip_writer_add_mem* | ||||
|  | ||||
| ### 2.0.7 | ||||
|  | ||||
|  - Removed need in C++ compiler in cmake build | ||||
|  - Fixed a lot of uninitialized value errors found with Valgrind by memsetting m_dict to 0 in tdefl_init | ||||
|  - Fix resource leak in mz_zip_reader_init_file_v2 | ||||
|  - Fix assert with mz_zip_writer_add_mem* w/MZ_DEFAULT_COMPRESSION | ||||
|  - cmake build: install library and headers | ||||
|  - Remove _LARGEFILE64_SOURCE requirement from apple defines for large files | ||||
|  | ||||
| ### 2.0.6 | ||||
|  | ||||
|  - Improve MZ_ZIP_FLAG_WRITE_ZIP64 documentation | ||||
|  - Remove check for cur_archive_file_ofs > UINT_MAX because cur_archive_file_ofs is not used after this point | ||||
|  - Add cmake debug configuration | ||||
|  - Fix PNG height when creating png files | ||||
|  - Add "iterative" file extraction method based on mz_zip_reader_extract_to_callback. | ||||
|  - Option to use memcpy for unaligned data access | ||||
|  - Define processor/arch macros as zero if not set to one | ||||
|  | ||||
| ### 2.0.4/2.0.5 | ||||
|  | ||||
|  - Fix compilation with the various omission compile definitions | ||||
|  | ||||
| ### 2.0.3 | ||||
|  | ||||
| - Fix GCC/clang compile warnings | ||||
| @@ -19,11 +84,12 @@ | ||||
|  | ||||
| ### 2.0.0 beta | ||||
|  | ||||
| - Matthew Sitton merged to vogl ZIP64 changes. Miniz is now licensed as MIT since the vogl code base is MIT licensed | ||||
| - Matthew Sitton merged miniz 1.x to Rich Geldreich's vogl ZIP64 changes. Miniz is now licensed as MIT since the vogl code base is MIT licensed | ||||
| - Miniz is now split into several files | ||||
| - Miniz does now not seek backwards when creating ZIP files. That is the ZIP files can be streamed | ||||
| - Miniz automatically switches to the ZIP64 format the created ZIP files goes over ZIP file limits | ||||
| - Miniz automatically switches to the ZIP64 format when the created ZIP files goes over ZIP file limits | ||||
| - Similar to [SQLite](https://www.sqlite.org/amalgamation.html) the Miniz source code is amalgamated into one miniz.c/miniz.h pair in a build step (amalgamate.sh). Please use miniz.c/miniz.h in your projects | ||||
| - Miniz 2 is only source back-compatible with miniz 1.x. It breaks binary compatibility because structures changed | ||||
|  | ||||
| ### v1.16 BETA Oct 19, 2013 | ||||
|  | ||||
| @@ -36,7 +102,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. | ||||
|   | ||||
							
								
								
									
										1
									
								
								Config.cmake.in
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										1
									
								
								Config.cmake.in
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1 @@ | ||||
| include("${CMAKE_CURRENT_LIST_DIR}/@PROJECT_NAME@Targets.cmake") | ||||
| @@ -3,47 +3,51 @@ | ||||
| set -e | ||||
|  | ||||
| mkdir -p amalgamation | ||||
| OUTPUT_PREFIX=amalgamation/miniz | ||||
|  | ||||
| cat miniz.h > $OUTPUT_PREFIX.h | ||||
| cat miniz.c > $OUTPUT_PREFIX.c | ||||
| cat miniz_common.h >> $OUTPUT_PREFIX.h | ||||
| cat miniz_tdef.c >> $OUTPUT_PREFIX.c | ||||
| cat miniz_tdef.h >> $OUTPUT_PREFIX.h | ||||
| cat miniz_tinfl.c >> $OUTPUT_PREFIX.c | ||||
| cat miniz_tinfl.h >> $OUTPUT_PREFIX.h | ||||
| cat miniz_zip.c >> $OUTPUT_PREFIX.c | ||||
| cat miniz_zip.h >> $OUTPUT_PREFIX.h | ||||
| OUTPUT_PREFIX=_build/amalgamation | ||||
|  | ||||
|  | ||||
| sed -i '0,/#include "miniz.h"/{s/#include "miniz.h"/#include  "miniz.h"/}' $OUTPUT_PREFIX.c | ||||
| for i in miniz miniz_common miniz_tdef miniz_tinfl miniz_zip | ||||
| do | ||||
| 	sed -i "s/#include \"$i.h\"//g" $OUTPUT_PREFIX.h | ||||
| 	sed -i "s/#include \"$i.h\"//g" $OUTPUT_PREFIX.c | ||||
| done | ||||
| cmake -H. -B_build -DAMALGAMATE_SOURCES=ON -G"Unix Makefiles" | ||||
|  | ||||
| echo "int main() { return 0; }" > main.c | ||||
| echo "Test compile with GCC..." | ||||
| gcc -pedantic -Wall main.c $OUTPUT_PREFIX.c -o test.out | ||||
| gcc -pedantic -Wall -I$OUTPUT_PREFIX main.c $OUTPUT_PREFIX/miniz.c -o test.out | ||||
| echo "Test compile with GCC ANSI..." | ||||
| gcc -ansi -pedantic -Wall main.c $OUTPUT_PREFIX.c -o test.out | ||||
| gcc -ansi -pedantic -Wall -I$OUTPUT_PREFIX main.c $OUTPUT_PREFIX/miniz.c -o test.out | ||||
| if command -v clang | ||||
| then | ||||
| 		echo "Test compile with clang..." | ||||
|         clang -Wall -Wpedantic -fsanitize=unsigned-integer-overflow main.c $OUTPUT_PREFIX.c -o test.out | ||||
|         clang -Wall -Wpedantic -fsanitize=unsigned-integer-overflow -I$OUTPUT_PREFIX main.c $OUTPUT_PREFIX/miniz.c -o test.out | ||||
| fi | ||||
| for def in MINIZ_NO_STDIO MINIZ_NO_TIME MINIZ_NO_ARCHIVE_APIS MINIZ_NO_ARCHIVE_WRITING_APIS MINIZ_NO_ZLIB_APIS MINIZ_NO_ZLIB_COMPATIBLE_NAMES MINIZ_NO_MALLOC | ||||
| do | ||||
| 	echo "Test compile with GCC and define $def..." | ||||
| 	gcc -ansi -pedantic -Wall main.c $OUTPUT_PREFIX.c -o test.out -D${def} | ||||
| 	gcc -ansi -pedantic -Wall -I$OUTPUT_PREFIX main.c $OUTPUT_PREFIX/miniz.c -o test.out -D${def} | ||||
| done | ||||
| rm test.out | ||||
| rm main.c | ||||
|  | ||||
| cp $OUTPUT_PREFIX/miniz.* amalgamation/ | ||||
| cp ChangeLog.md amalgamation/ | ||||
| cp LICENSE amalgamation/ | ||||
| cp readme.md amalgamation/ | ||||
| mkdir -p amalgamation/examples | ||||
| cp examples/* amalgamation/examples/ | ||||
|  | ||||
| cd amalgamation | ||||
| ! test -e miniz.zip || rm miniz.zip | ||||
| echo -e "miniz.c\nminiz.h" | zip -@ miniz | ||||
| cat << EOF | zip -@ miniz | ||||
| miniz.c | ||||
| miniz.h | ||||
| ChangeLog.md | ||||
| LICENSE | ||||
| readme.md | ||||
| examples/example1.c | ||||
| examples/example2.c | ||||
| examples/example3.c | ||||
| examples/example4.c | ||||
| examples/example5.c | ||||
| examples/example6.c | ||||
| EOF | ||||
| cd .. | ||||
|  | ||||
| echo "Amalgamation created." | ||||
|   | ||||
| @@ -13,7 +13,7 @@ | ||||
| #endif | ||||
|  | ||||
| #include <stdio.h> | ||||
| #include "miniz_zip.h" | ||||
| #include "miniz.h" | ||||
|  | ||||
| typedef unsigned char uint8; | ||||
| typedef unsigned short uint16; | ||||
|   | ||||
| @@ -1,6 +1,6 @@ | ||||
| // example4.c - Uses tinfl.c to decompress a zlib stream in memory to an output file | ||||
| // Public domain, May 15 2011, Rich Geldreich, richgel99@gmail.com. See "unlicense" statement at the end of tinfl.c. | ||||
| #include "miniz_tinfl.h" | ||||
| #include "miniz.h" | ||||
| #include <stdio.h> | ||||
| #include <limits.h> | ||||
|  | ||||
|   | ||||
							
								
								
									
										21
									
								
								meson.build
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										21
									
								
								meson.build
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,21 @@ | ||||
| project('miniz', 'c') | ||||
|  | ||||
| miniz_includes = include_directories('.') | ||||
|  | ||||
| cfg = configuration_data() | ||||
| cfg.set('MINIZ_EXPORT', '') | ||||
| miniz_export_h = configure_file(output: 'miniz_export.h', | ||||
|                                 configuration: cfg) | ||||
|  | ||||
| libminiz = static_library('miniz', | ||||
|                           miniz_export_h, 'miniz.c', 'miniz_zip.c', 'miniz_tinfl.c', 'miniz_tdef.c', | ||||
|                           include_directories: miniz_includes) | ||||
|  | ||||
| miniz_dependency = declare_dependency(link_with: libminiz, | ||||
|                                       include_directories: miniz_includes) | ||||
|                                        | ||||
| miniz_dep = miniz_dependency # Compatibility for WrapDB users | ||||
|  | ||||
| if meson.version().version_compare('>= 0.54.0') | ||||
|     meson.override_dependency('miniz', miniz_dep) | ||||
| endif | ||||
							
								
								
									
										51
									
								
								miniz.c
									
									
									
									
									
								
							
							
						
						
									
										51
									
								
								miniz.c
									
									
									
									
									
								
							| @@ -82,6 +82,12 @@ mz_ulong mz_adler32(mz_ulong adler, const unsigned char *ptr, size_t buf_len) | ||||
|         } | ||||
|         return ~crcu32; | ||||
|     } | ||||
| #elif defined(USE_EXTERNAL_MZCRC) | ||||
| /* If USE_EXTERNAL_CRC is defined, an external module will export the | ||||
|  * mz_crc32() symbol for us to use, e.g. an SSE-accelerated version. | ||||
|  * Depending on the impl, it may be necessary to ~ the input/output crc values. | ||||
|  */ | ||||
| mz_ulong mz_crc32(mz_ulong crc, const mz_uint8 *ptr, size_t buf_len); | ||||
| #else | ||||
| /* Faster, but larger CPU cache footprint. | ||||
|  */ | ||||
| @@ -157,17 +163,17 @@ void mz_free(void *p) | ||||
|     MZ_FREE(p); | ||||
| } | ||||
|  | ||||
| void *miniz_def_alloc_func(void *opaque, size_t items, size_t size) | ||||
| MINIZ_EXPORT void *miniz_def_alloc_func(void *opaque, size_t items, size_t size) | ||||
| { | ||||
|     (void)opaque, (void)items, (void)size; | ||||
|     return MZ_MALLOC(items * size); | ||||
| } | ||||
| void miniz_def_free_func(void *opaque, void *address) | ||||
| MINIZ_EXPORT void miniz_def_free_func(void *opaque, void *address) | ||||
| { | ||||
|     (void)opaque, (void)address; | ||||
|     MZ_FREE(address); | ||||
| } | ||||
| void *miniz_def_realloc_func(void *opaque, void *address, size_t items, size_t size) | ||||
| MINIZ_EXPORT void *miniz_def_realloc_func(void *opaque, void *address, size_t items, size_t size) | ||||
| { | ||||
|     (void)opaque, (void)address, (void)items, (void)size; | ||||
|     return MZ_REALLOC(address, items * size); | ||||
| @@ -397,6 +403,32 @@ int mz_inflateInit(mz_streamp pStream) | ||||
|     return mz_inflateInit2(pStream, MZ_DEFAULT_WINDOW_BITS); | ||||
| } | ||||
|  | ||||
| int mz_inflateReset(mz_streamp pStream) | ||||
| { | ||||
|     inflate_state *pDecomp; | ||||
|     if (!pStream) | ||||
|         return MZ_STREAM_ERROR; | ||||
|  | ||||
|     pStream->data_type = 0; | ||||
|     pStream->adler = 0; | ||||
|     pStream->msg = NULL; | ||||
|     pStream->total_in = 0; | ||||
|     pStream->total_out = 0; | ||||
|     pStream->reserved = 0; | ||||
|  | ||||
|     pDecomp = (inflate_state *)pStream->state; | ||||
|  | ||||
|     tinfl_init(&pDecomp->m_decomp); | ||||
|     pDecomp->m_dict_ofs = 0; | ||||
|     pDecomp->m_dict_avail = 0; | ||||
|     pDecomp->m_last_status = TINFL_STATUS_NEEDS_MORE_INPUT; | ||||
|     pDecomp->m_first_call = 1; | ||||
|     pDecomp->m_has_flushed = 0; | ||||
|     /* pDecomp->m_window_bits = window_bits */; | ||||
|  | ||||
|     return MZ_OK; | ||||
| } | ||||
|  | ||||
| int mz_inflate(mz_streamp pStream, int flush) | ||||
| { | ||||
|     inflate_state *pState; | ||||
| @@ -520,19 +552,18 @@ int mz_inflateEnd(mz_streamp pStream) | ||||
|     } | ||||
|     return MZ_OK; | ||||
| } | ||||
|  | ||||
| int mz_uncompress(unsigned char *pDest, mz_ulong *pDest_len, const unsigned char *pSource, mz_ulong source_len) | ||||
| int mz_uncompress2(unsigned char *pDest, mz_ulong *pDest_len, const unsigned char *pSource, mz_ulong *pSource_len) | ||||
| { | ||||
|     mz_stream stream; | ||||
|     int status; | ||||
|     memset(&stream, 0, sizeof(stream)); | ||||
|  | ||||
|     /* In case mz_ulong is 64-bits (argh I hate longs). */ | ||||
|     if ((source_len | *pDest_len) > 0xFFFFFFFFU) | ||||
|     if ((*pSource_len | *pDest_len) > 0xFFFFFFFFU) | ||||
|         return MZ_PARAM_ERROR; | ||||
|  | ||||
|     stream.next_in = pSource; | ||||
|     stream.avail_in = (mz_uint32)source_len; | ||||
|     stream.avail_in = (mz_uint32)*pSource_len; | ||||
|     stream.next_out = pDest; | ||||
|     stream.avail_out = (mz_uint32)*pDest_len; | ||||
|  | ||||
| @@ -541,6 +572,7 @@ int mz_uncompress(unsigned char *pDest, mz_ulong *pDest_len, const unsigned char | ||||
|         return status; | ||||
|  | ||||
|     status = mz_inflate(&stream, MZ_FINISH); | ||||
|     *pSource_len = *pSource_len - stream.avail_in; | ||||
|     if (status != MZ_STREAM_END) | ||||
|     { | ||||
|         mz_inflateEnd(&stream); | ||||
| @@ -551,6 +583,11 @@ int mz_uncompress(unsigned char *pDest, mz_ulong *pDest_len, const unsigned char | ||||
|     return mz_inflateEnd(&stream); | ||||
| } | ||||
|  | ||||
| int mz_uncompress(unsigned char *pDest, mz_ulong *pDest_len, const unsigned char *pSource, mz_ulong source_len) | ||||
| { | ||||
|     return mz_uncompress2(pDest, pDest_len, pSource, &source_len); | ||||
| } | ||||
|  | ||||
| const char *mz_error(int err) | ||||
| { | ||||
|     static struct | ||||
|   | ||||
							
								
								
									
										73
									
								
								miniz.h
									
									
									
									
									
								
							
							
						
						
									
										73
									
								
								miniz.h
									
									
									
									
									
								
							| @@ -1,4 +1,4 @@ | ||||
| /* miniz.c 2.0.7 - public domain deflate/inflate, zlib-subset, ZIP reading/writing/appending, PNG writing | ||||
| /* miniz.c 2.2.0 - public domain deflate/inflate, zlib-subset, ZIP reading/writing/appending, PNG writing | ||||
|    See "unlicense" statement at the end of this file. | ||||
|    Rich Geldreich <richgel99@gmail.com>, last updated Oct. 13, 2013 | ||||
|    Implements RFC 1950: http://www.ietf.org/rfc/rfc1950.txt and RFC 1951: http://www.ietf.org/rfc/rfc1951.txt | ||||
| @@ -24,7 +24,7 @@ | ||||
|      zlib replacement in many apps: | ||||
|         The z_stream struct, optional memory allocation callbacks | ||||
|         deflateInit/deflateInit2/deflate/deflateReset/deflateEnd/deflateBound | ||||
|         inflateInit/inflateInit2/inflate/inflateEnd | ||||
|         inflateInit/inflateInit2/inflate/inflateReset/inflateEnd | ||||
|         compress, compress2, compressBound, uncompress | ||||
|         CRC-32, Adler-32 - Using modern, minimal code size, CPU cache friendly routines. | ||||
|         Supports raw deflate streams or standard zlib streams with adler-32 checking. | ||||
| @@ -95,7 +95,7 @@ | ||||
|      possibility that the archive's central directory could be lost with this method if anything goes wrong, though. | ||||
|  | ||||
|      - ZIP archive support limitations: | ||||
|      No zip64 or spanning support. Extraction functions can only handle unencrypted, stored or deflated files. | ||||
|      No spanning support. Extraction functions can only handle unencrypted, stored or deflated files. | ||||
|      Requires streams capable of seeking. | ||||
|  | ||||
|    * This is a header file library, like stb_image.c. To get only a header file, either cut and paste the | ||||
| @@ -112,9 +112,7 @@ | ||||
| */ | ||||
| #pragma once | ||||
|  | ||||
| #include "miniz_common.h" | ||||
| #include "miniz_tdef.h" | ||||
| #include "miniz_tinfl.h" | ||||
| #include "miniz_export.h" | ||||
|  | ||||
| /* Defines to completely disable specific portions of miniz.c:  | ||||
|    If all macros here are defined the only functionality remaining will be CRC-32, adler-32, tinfl, and tdefl. */ | ||||
| @@ -170,12 +168,16 @@ | ||||
| #define MINIZ_LITTLE_ENDIAN 0 | ||||
| #endif | ||||
|  | ||||
| /* Set MINIZ_USE_UNALIGNED_LOADS_AND_STORES only if not set */ | ||||
| #if !defined(MINIZ_USE_UNALIGNED_LOADS_AND_STORES) | ||||
| #if MINIZ_X86_OR_X64_CPU | ||||
| /* Set MINIZ_USE_UNALIGNED_LOADS_AND_STORES to 1 on CPU's that permit efficient integer loads and stores from unaligned addresses. */ | ||||
| #define MINIZ_USE_UNALIGNED_LOADS_AND_STORES 1 | ||||
| #define MINIZ_UNALIGNED_USE_MEMCPY | ||||
| #else | ||||
| #define MINIZ_USE_UNALIGNED_LOADS_AND_STORES 0 | ||||
| #endif | ||||
| #endif | ||||
|  | ||||
| #if defined(_M_X64) || defined(_WIN64) || defined(__MINGW64__) || defined(_LP64) || defined(__LP64__) || defined(__ia64__) || defined(__x86_64__) | ||||
| /* Set MINIZ_HAS_64BIT_REGISTERS to 1 if operations on 64-bit integers are reasonably fast (and don't involve compiler generated calls to helper functions). */ | ||||
| @@ -194,15 +196,15 @@ extern "C" { | ||||
| typedef unsigned long mz_ulong; | ||||
|  | ||||
| /* mz_free() internally uses the MZ_FREE() macro (which by default calls free() unless you've modified the MZ_MALLOC macro) to release a block allocated from the heap. */ | ||||
| void mz_free(void *p); | ||||
| MINIZ_EXPORT void mz_free(void *p); | ||||
|  | ||||
| #define MZ_ADLER32_INIT (1) | ||||
| /* mz_adler32() returns the initial adler-32 value to use when called with ptr==NULL. */ | ||||
| mz_ulong mz_adler32(mz_ulong adler, const unsigned char *ptr, size_t buf_len); | ||||
| MINIZ_EXPORT mz_ulong mz_adler32(mz_ulong adler, const unsigned char *ptr, size_t buf_len); | ||||
|  | ||||
| #define MZ_CRC32_INIT (0) | ||||
| /* mz_crc32() returns the initial CRC-32 value to use when called with ptr==NULL. */ | ||||
| mz_ulong mz_crc32(mz_ulong crc, const unsigned char *ptr, size_t buf_len); | ||||
| MINIZ_EXPORT mz_ulong mz_crc32(mz_ulong crc, const unsigned char *ptr, size_t buf_len); | ||||
|  | ||||
| /* Compression strategies. */ | ||||
| enum | ||||
| @@ -218,7 +220,7 @@ enum | ||||
| #define MZ_DEFLATED 8 | ||||
|  | ||||
| /* Heap allocation callbacks. | ||||
| Note that mz_alloc_func parameter types purpsosely differ from zlib's: items/size is size_t, not unsigned long. */ | ||||
| Note that mz_alloc_func parameter types purposely differ from zlib's: items/size is size_t, not unsigned long. */ | ||||
| typedef void *(*mz_alloc_func)(void *opaque, size_t items, size_t size); | ||||
| typedef void (*mz_free_func)(void *opaque, void *address); | ||||
| typedef void *(*mz_realloc_func)(void *opaque, void *address, size_t items, size_t size); | ||||
| @@ -234,11 +236,11 @@ enum | ||||
|     MZ_DEFAULT_COMPRESSION = -1 | ||||
| }; | ||||
|  | ||||
| #define MZ_VERSION "10.0.2" | ||||
| #define MZ_VERNUM 0xA020 | ||||
| #define MZ_VERSION "10.2.0" | ||||
| #define MZ_VERNUM 0xA100 | ||||
| #define MZ_VER_MAJOR 10 | ||||
| #define MZ_VER_MINOR 0 | ||||
| #define MZ_VER_REVISION 2 | ||||
| #define MZ_VER_MINOR 2 | ||||
| #define MZ_VER_REVISION 0 | ||||
| #define MZ_VER_SUBREVISION 0 | ||||
|  | ||||
| #ifndef MINIZ_NO_ZLIB_APIS | ||||
| @@ -300,7 +302,7 @@ typedef struct mz_stream_s | ||||
| typedef mz_stream *mz_streamp; | ||||
|  | ||||
| /* Returns the version string of miniz.c. */ | ||||
| const char *mz_version(void); | ||||
| MINIZ_EXPORT const char *mz_version(void); | ||||
|  | ||||
| /* mz_deflateInit() initializes a compressor with default options: */ | ||||
| /* Parameters: */ | ||||
| @@ -313,17 +315,17 @@ const char *mz_version(void); | ||||
| /*  MZ_STREAM_ERROR if the stream is bogus. */ | ||||
| /*  MZ_PARAM_ERROR if the input parameters are bogus. */ | ||||
| /*  MZ_MEM_ERROR on out of memory. */ | ||||
| int mz_deflateInit(mz_streamp pStream, int level); | ||||
| MINIZ_EXPORT int mz_deflateInit(mz_streamp pStream, int level); | ||||
|  | ||||
| /* mz_deflateInit2() is like mz_deflate(), except with more control: */ | ||||
| /* Additional parameters: */ | ||||
| /*   method must be MZ_DEFLATED */ | ||||
| /*   window_bits must be MZ_DEFAULT_WINDOW_BITS (to wrap the deflate stream with zlib header/adler-32 footer) or -MZ_DEFAULT_WINDOW_BITS (raw deflate/no header or footer) */ | ||||
| /*   mem_level must be between [1, 9] (it's checked but ignored by miniz.c) */ | ||||
| int mz_deflateInit2(mz_streamp pStream, int level, int method, int window_bits, int mem_level, int strategy); | ||||
| MINIZ_EXPORT int mz_deflateInit2(mz_streamp pStream, int level, int method, int window_bits, int mem_level, int strategy); | ||||
|  | ||||
| /* Quickly resets a compressor without having to reallocate anything. Same as calling mz_deflateEnd() followed by mz_deflateInit()/mz_deflateInit2(). */ | ||||
| int mz_deflateReset(mz_streamp pStream); | ||||
| MINIZ_EXPORT int mz_deflateReset(mz_streamp pStream); | ||||
|  | ||||
| /* mz_deflate() compresses the input to output, consuming as much of the input and producing as much output as possible. */ | ||||
| /* Parameters: */ | ||||
| @@ -335,31 +337,34 @@ int mz_deflateReset(mz_streamp pStream); | ||||
| /*   MZ_STREAM_ERROR if the stream is bogus. */ | ||||
| /*   MZ_PARAM_ERROR if one of the parameters is invalid. */ | ||||
| /*   MZ_BUF_ERROR if no forward progress is possible because the input and/or output buffers are empty. (Fill up the input buffer or free up some output space and try again.) */ | ||||
| int mz_deflate(mz_streamp pStream, int flush); | ||||
| MINIZ_EXPORT int mz_deflate(mz_streamp pStream, int flush); | ||||
|  | ||||
| /* mz_deflateEnd() deinitializes a compressor: */ | ||||
| /* Return values: */ | ||||
| /*  MZ_OK on success. */ | ||||
| /*  MZ_STREAM_ERROR if the stream is bogus. */ | ||||
| int mz_deflateEnd(mz_streamp pStream); | ||||
| MINIZ_EXPORT int mz_deflateEnd(mz_streamp pStream); | ||||
|  | ||||
| /* mz_deflateBound() returns a (very) conservative upper bound on the amount of data that could be generated by deflate(), assuming flush is set to only MZ_NO_FLUSH or MZ_FINISH. */ | ||||
| mz_ulong mz_deflateBound(mz_streamp pStream, mz_ulong source_len); | ||||
| MINIZ_EXPORT mz_ulong mz_deflateBound(mz_streamp pStream, mz_ulong source_len); | ||||
|  | ||||
| /* Single-call compression functions mz_compress() and mz_compress2(): */ | ||||
| /* Returns MZ_OK on success, or one of the error codes from mz_deflate() on failure. */ | ||||
| int mz_compress(unsigned char *pDest, mz_ulong *pDest_len, const unsigned char *pSource, mz_ulong source_len); | ||||
| int mz_compress2(unsigned char *pDest, mz_ulong *pDest_len, const unsigned char *pSource, mz_ulong source_len, int level); | ||||
| MINIZ_EXPORT int mz_compress(unsigned char *pDest, mz_ulong *pDest_len, const unsigned char *pSource, mz_ulong source_len); | ||||
| MINIZ_EXPORT int mz_compress2(unsigned char *pDest, mz_ulong *pDest_len, const unsigned char *pSource, mz_ulong source_len, int level); | ||||
|  | ||||
| /* mz_compressBound() returns a (very) conservative upper bound on the amount of data that could be generated by calling mz_compress(). */ | ||||
| mz_ulong mz_compressBound(mz_ulong source_len); | ||||
| MINIZ_EXPORT mz_ulong mz_compressBound(mz_ulong source_len); | ||||
|  | ||||
| /* Initializes a decompressor. */ | ||||
| int mz_inflateInit(mz_streamp pStream); | ||||
| MINIZ_EXPORT int mz_inflateInit(mz_streamp pStream); | ||||
|  | ||||
| /* mz_inflateInit2() is like mz_inflateInit() with an additional option that controls the window size and whether or not the stream has been wrapped with a zlib header/footer: */ | ||||
| /* window_bits must be MZ_DEFAULT_WINDOW_BITS (to parse zlib header/footer) or -MZ_DEFAULT_WINDOW_BITS (raw deflate). */ | ||||
| int mz_inflateInit2(mz_streamp pStream, int window_bits); | ||||
| MINIZ_EXPORT int mz_inflateInit2(mz_streamp pStream, int window_bits); | ||||
|  | ||||
| /* Quickly resets a compressor without having to reallocate anything. Same as calling mz_inflateEnd() followed by mz_inflateInit()/mz_inflateInit2(). */ | ||||
| MINIZ_EXPORT int mz_inflateReset(mz_streamp pStream); | ||||
|  | ||||
| /* Decompresses the input stream to the output, consuming only as much of the input as needed, and writing as much to the output as possible. */ | ||||
| /* Parameters: */ | ||||
| @@ -375,17 +380,18 @@ int mz_inflateInit2(mz_streamp pStream, int window_bits); | ||||
| /*   MZ_PARAM_ERROR if one of the parameters is invalid. */ | ||||
| /*   MZ_BUF_ERROR if no forward progress is possible because the input buffer is empty but the inflater needs more input to continue, or if the output buffer is not large enough. Call mz_inflate() again */ | ||||
| /*   with more input data, or with more room in the output buffer (except when using single call decompression, described above). */ | ||||
| int mz_inflate(mz_streamp pStream, int flush); | ||||
| MINIZ_EXPORT int mz_inflate(mz_streamp pStream, int flush); | ||||
|  | ||||
| /* Deinitializes a decompressor. */ | ||||
| int mz_inflateEnd(mz_streamp pStream); | ||||
| MINIZ_EXPORT int mz_inflateEnd(mz_streamp pStream); | ||||
|  | ||||
| /* Single-call decompression. */ | ||||
| /* Returns MZ_OK on success, or one of the error codes from mz_inflate() on failure. */ | ||||
| int mz_uncompress(unsigned char *pDest, mz_ulong *pDest_len, const unsigned char *pSource, mz_ulong source_len); | ||||
| MINIZ_EXPORT int mz_uncompress(unsigned char *pDest, mz_ulong *pDest_len, const unsigned char *pSource, mz_ulong source_len); | ||||
| MINIZ_EXPORT int mz_uncompress2(unsigned char *pDest, mz_ulong *pDest_len, const unsigned char *pSource, mz_ulong *pSource_len); | ||||
|  | ||||
| /* Returns a string description of the specified error code, or NULL if the error code is invalid. */ | ||||
| const char *mz_error(int err); | ||||
| MINIZ_EXPORT const char *mz_error(int err); | ||||
|  | ||||
| /* Redefine zlib-compatible names to miniz equivalents, so miniz.c can be used as a drop-in replacement for the subset of zlib that miniz.c supports. */ | ||||
| /* Define MINIZ_NO_ZLIB_COMPATIBLE_NAMES to disable zlib-compatibility if you use zlib in the same project. */ | ||||
| @@ -444,9 +450,11 @@ typedef void *const voidpc; | ||||
| #define compressBound mz_compressBound | ||||
| #define inflateInit mz_inflateInit | ||||
| #define inflateInit2 mz_inflateInit2 | ||||
| #define inflateReset mz_inflateReset | ||||
| #define inflate mz_inflate | ||||
| #define inflateEnd mz_inflateEnd | ||||
| #define uncompress mz_uncompress | ||||
| #define uncompress2 mz_uncompress2 | ||||
| #define crc32 mz_crc32 | ||||
| #define adler32 mz_adler32 | ||||
| #define MAX_WBITS 15 | ||||
| @@ -467,3 +475,8 @@ typedef void *const voidpc; | ||||
| #ifdef __cplusplus | ||||
| } | ||||
| #endif | ||||
|  | ||||
| #include "miniz_common.h" | ||||
| #include "miniz_tdef.h" | ||||
| #include "miniz_tinfl.h" | ||||
| #include "miniz_zip.h" | ||||
|   | ||||
							
								
								
									
										13
									
								
								miniz.pc.in
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										13
									
								
								miniz.pc.in
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,13 @@ | ||||
| prefix=@CMAKE_INSTALL_PREFIX@ | ||||
| exec_prefix=${prefix} | ||||
| libdir=${exec_prefix}/@CMAKE_INSTALL_LIBDIR@ | ||||
| includedir=${prefix}/@CMAKE_INSTALL_INCLUDEDIR@ | ||||
|  | ||||
| Name: @PROJECT_NAME@ | ||||
| Description: @PROJECT_DESCRIPTION@ | ||||
| Version: @MINIZ_VERSION@ | ||||
| URL: @PROJECT_HOMEPAGE_URL@ | ||||
|  | ||||
| Requires: | ||||
| Libs: -L${libdir} -lminiz | ||||
| Cflags: -I${includedir} | ||||
| @@ -4,6 +4,8 @@ | ||||
| #include <stdlib.h> | ||||
| #include <string.h> | ||||
|  | ||||
| #include "miniz_export.h" | ||||
|  | ||||
| /* ------------------- Types and macros */ | ||||
| typedef unsigned char mz_uint8; | ||||
| typedef signed short mz_int16; | ||||
| @@ -79,9 +81,9 @@ typedef struct mz_dummy_time_t_tag | ||||
| extern "C" { | ||||
| #endif | ||||
|  | ||||
| extern void *miniz_def_alloc_func(void *opaque, size_t items, size_t size); | ||||
| extern void miniz_def_free_func(void *opaque, void *address); | ||||
| extern void *miniz_def_realloc_func(void *opaque, void *address, size_t items, size_t size); | ||||
| extern MINIZ_EXPORT void *miniz_def_alloc_func(void *opaque, size_t items, size_t size); | ||||
| extern MINIZ_EXPORT void miniz_def_free_func(void *opaque, void *address); | ||||
| extern MINIZ_EXPORT void *miniz_def_realloc_func(void *opaque, void *address, size_t items, size_t size); | ||||
|  | ||||
| #define MZ_UINT16_MAX (0xFFFFU) | ||||
| #define MZ_UINT32_MAX (0xFFFFFFFFU) | ||||
|   | ||||
							
								
								
									
										30
									
								
								miniz_tdef.c
									
									
									
									
									
								
							
							
						
						
									
										30
									
								
								miniz_tdef.c
									
									
									
									
									
								
							| @@ -24,7 +24,6 @@ | ||||
|  * | ||||
|  **************************************************************************/ | ||||
|  | ||||
| #include "miniz_tdef.h" | ||||
| #include "miniz.h" | ||||
|  | ||||
| #ifdef __cplusplus | ||||
| @@ -738,13 +737,13 @@ static int tdefl_flush_block(tdefl_compressor *d, int flush) | ||||
|  | ||||
| #if MINIZ_USE_UNALIGNED_LOADS_AND_STORES | ||||
| #ifdef MINIZ_UNALIGNED_USE_MEMCPY | ||||
| static inline mz_uint16 TDEFL_READ_UNALIGNED_WORD(const mz_uint8* p) | ||||
| static mz_uint16 TDEFL_READ_UNALIGNED_WORD(const mz_uint8* p) | ||||
| { | ||||
| 	mz_uint16 ret; | ||||
| 	memcpy(&ret, p, sizeof(mz_uint16)); | ||||
| 	return ret; | ||||
| } | ||||
| static inline mz_uint16 TDEFL_READ_UNALIGNED_WORD2(const mz_uint16* p) | ||||
| static mz_uint16 TDEFL_READ_UNALIGNED_WORD2(const mz_uint16* p) | ||||
| { | ||||
| 	mz_uint16 ret; | ||||
| 	memcpy(&ret, p, sizeof(mz_uint16)); | ||||
| @@ -853,6 +852,16 @@ static MZ_FORCEINLINE void tdefl_find_match(tdefl_compressor *d, mz_uint lookahe | ||||
| #endif /* #if MINIZ_USE_UNALIGNED_LOADS_AND_STORES */ | ||||
|  | ||||
| #if MINIZ_USE_UNALIGNED_LOADS_AND_STORES && MINIZ_LITTLE_ENDIAN | ||||
| #ifdef MINIZ_UNALIGNED_USE_MEMCPY | ||||
| static mz_uint32 TDEFL_READ_UNALIGNED_WORD32(const mz_uint8* p) | ||||
| { | ||||
| 	mz_uint32 ret; | ||||
| 	memcpy(&ret, p, sizeof(mz_uint32)); | ||||
| 	return ret; | ||||
| } | ||||
| #else | ||||
| #define TDEFL_READ_UNALIGNED_WORD32(p) *(const mz_uint32 *)(p) | ||||
| #endif | ||||
| static mz_bool tdefl_compress_fast(tdefl_compressor *d) | ||||
| { | ||||
|     /* Faster, minimally featured LZRW1-style match+parse loop with better register utilization. Intended for applications where raw throughput is valued more highly than ratio. */ | ||||
| @@ -887,12 +896,12 @@ static mz_bool tdefl_compress_fast(tdefl_compressor *d) | ||||
|         { | ||||
|             mz_uint cur_match_dist, cur_match_len = 1; | ||||
|             mz_uint8 *pCur_dict = d->m_dict + cur_pos; | ||||
|             mz_uint first_trigram = (*(const mz_uint32 *)pCur_dict) & 0xFFFFFF; | ||||
|             mz_uint first_trigram = TDEFL_READ_UNALIGNED_WORD32(pCur_dict) & 0xFFFFFF; | ||||
|             mz_uint hash = (first_trigram ^ (first_trigram >> (24 - (TDEFL_LZ_HASH_BITS - 8)))) & TDEFL_LEVEL1_HASH_SIZE_MASK; | ||||
|             mz_uint probe_pos = d->m_hash[hash]; | ||||
|             d->m_hash[hash] = (mz_uint16)lookahead_pos; | ||||
|  | ||||
|             if (((cur_match_dist = (mz_uint16)(lookahead_pos - probe_pos)) <= dict_size) && ((*(const mz_uint32 *)(d->m_dict + (probe_pos &= TDEFL_LZ_DICT_SIZE_MASK)) & 0xFFFFFF) == first_trigram)) | ||||
|             if (((cur_match_dist = (mz_uint16)(lookahead_pos - probe_pos)) <= dict_size) && ((TDEFL_READ_UNALIGNED_WORD32(d->m_dict + (probe_pos &= TDEFL_LZ_DICT_SIZE_MASK)) & 0xFFFFFF) == first_trigram)) | ||||
|             { | ||||
|                 const mz_uint16 *p = (const mz_uint16 *)pCur_dict; | ||||
|                 const mz_uint16 *q = (const mz_uint16 *)(d->m_dict + probe_pos); | ||||
| @@ -922,7 +931,11 @@ static mz_bool tdefl_compress_fast(tdefl_compressor *d) | ||||
|                     cur_match_dist--; | ||||
|  | ||||
|                     pLZ_code_buf[0] = (mz_uint8)(cur_match_len - TDEFL_MIN_MATCH_LEN); | ||||
| #ifdef MINIZ_UNALIGNED_USE_MEMCPY | ||||
| 					memcpy(&pLZ_code_buf[1], &cur_match_dist, sizeof(cur_match_dist)); | ||||
| #else | ||||
|                     *(mz_uint16 *)(&pLZ_code_buf[1]) = (mz_uint16)cur_match_dist; | ||||
| #endif | ||||
|                     pLZ_code_buf += 3; | ||||
|                     *pLZ_flags = (mz_uint8)((*pLZ_flags >> 1) | 0x80); | ||||
|  | ||||
| @@ -1061,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) | ||||
| @@ -1320,6 +1331,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; | ||||
| @@ -1541,6 +1553,7 @@ void *tdefl_write_image_to_png_file_in_memory(const void *pImage, int w, int h, | ||||
|     return tdefl_write_image_to_png_file_in_memory_ex(pImage, w, h, num_chans, pLen_out, 6, MZ_FALSE); | ||||
| } | ||||
|  | ||||
| #ifndef MINIZ_NO_MALLOC | ||||
| /* Allocate the tdefl_compressor and tinfl_decompressor structures in C so that */ | ||||
| /* non-C language bindings to tdefL_ and tinfl_ API don't need to worry about */ | ||||
| /* structure size and allocation mechanism. */ | ||||
| @@ -1553,6 +1566,7 @@ void tdefl_compressor_free(tdefl_compressor *pComp) | ||||
| { | ||||
|     MZ_FREE(pComp); | ||||
| } | ||||
| #endif | ||||
|  | ||||
| #ifdef _MSC_VER | ||||
| #pragma warning(pop) | ||||
|   | ||||
							
								
								
									
										28
									
								
								miniz_tdef.h
									
									
									
									
									
								
							
							
						
						
									
										28
									
								
								miniz_tdef.h
									
									
									
									
									
								
							| @@ -48,11 +48,11 @@ enum | ||||
| /*  Function returns a pointer to the compressed data, or NULL on failure. */ | ||||
| /*  *pOut_len will be set to the compressed data's size, which could be larger than src_buf_len on uncompressible data. */ | ||||
| /*  The caller must free() the returned block when it's no longer needed. */ | ||||
| void *tdefl_compress_mem_to_heap(const void *pSrc_buf, size_t src_buf_len, size_t *pOut_len, int flags); | ||||
| MINIZ_EXPORT void *tdefl_compress_mem_to_heap(const void *pSrc_buf, size_t src_buf_len, size_t *pOut_len, int flags); | ||||
|  | ||||
| /* tdefl_compress_mem_to_mem() compresses a block in memory to another block in memory. */ | ||||
| /* Returns 0 on failure. */ | ||||
| size_t tdefl_compress_mem_to_mem(void *pOut_buf, size_t out_buf_len, const void *pSrc_buf, size_t src_buf_len, int flags); | ||||
| MINIZ_EXPORT size_t tdefl_compress_mem_to_mem(void *pOut_buf, size_t out_buf_len, const void *pSrc_buf, size_t src_buf_len, int flags); | ||||
|  | ||||
| /* Compresses an image to a compressed PNG file in memory. */ | ||||
| /* On entry: */ | ||||
| @@ -64,14 +64,14 @@ size_t tdefl_compress_mem_to_mem(void *pOut_buf, size_t out_buf_len, const void | ||||
| /*  Function returns a pointer to the compressed data, or NULL on failure. */ | ||||
| /*  *pLen_out will be set to the size of the PNG image file. */ | ||||
| /*  The caller must mz_free() the returned heap block (which will typically be larger than *pLen_out) when it's no longer needed. */ | ||||
| void *tdefl_write_image_to_png_file_in_memory_ex(const void *pImage, int w, int h, int num_chans, size_t *pLen_out, mz_uint level, mz_bool flip); | ||||
| void *tdefl_write_image_to_png_file_in_memory(const void *pImage, int w, int h, int num_chans, size_t *pLen_out); | ||||
| MINIZ_EXPORT void *tdefl_write_image_to_png_file_in_memory_ex(const void *pImage, int w, int h, int num_chans, size_t *pLen_out, mz_uint level, mz_bool flip); | ||||
| MINIZ_EXPORT void *tdefl_write_image_to_png_file_in_memory(const void *pImage, int w, int h, int num_chans, size_t *pLen_out); | ||||
|  | ||||
| /* Output stream interface. The compressor uses this interface to write compressed data. It'll typically be called TDEFL_OUT_BUF_SIZE at a time. */ | ||||
| typedef mz_bool (*tdefl_put_buf_func_ptr)(const void *pBuf, int len, void *pUser); | ||||
|  | ||||
| /* tdefl_compress_mem_to_output() compresses a block to an output stream. The above helpers use this function internally. */ | ||||
| mz_bool tdefl_compress_mem_to_output(const void *pBuf, size_t buf_len, tdefl_put_buf_func_ptr pPut_buf_func, void *pPut_buf_user, int flags); | ||||
| MINIZ_EXPORT mz_bool tdefl_compress_mem_to_output(const void *pBuf, size_t buf_len, tdefl_put_buf_func_ptr pPut_buf_func, void *pPut_buf_user, int flags); | ||||
|  | ||||
| enum | ||||
| { | ||||
| @@ -159,29 +159,31 @@ typedef struct | ||||
| /* pBut_buf_func: If NULL, output data will be supplied to the specified callback. In this case, the user should call the tdefl_compress_buffer() API for compression. */ | ||||
| /* If pBut_buf_func is NULL the user should always call the tdefl_compress() API. */ | ||||
| /* flags: See the above enums (TDEFL_HUFFMAN_ONLY, TDEFL_WRITE_ZLIB_HEADER, etc.) */ | ||||
| tdefl_status tdefl_init(tdefl_compressor *d, tdefl_put_buf_func_ptr pPut_buf_func, void *pPut_buf_user, int flags); | ||||
| MINIZ_EXPORT tdefl_status tdefl_init(tdefl_compressor *d, tdefl_put_buf_func_ptr pPut_buf_func, void *pPut_buf_user, int flags); | ||||
|  | ||||
| /* Compresses a block of data, consuming as much of the specified input buffer as possible, and writing as much compressed data to the specified output buffer as possible. */ | ||||
| tdefl_status tdefl_compress(tdefl_compressor *d, const void *pIn_buf, size_t *pIn_buf_size, void *pOut_buf, size_t *pOut_buf_size, tdefl_flush flush); | ||||
| MINIZ_EXPORT tdefl_status tdefl_compress(tdefl_compressor *d, const void *pIn_buf, size_t *pIn_buf_size, void *pOut_buf, size_t *pOut_buf_size, tdefl_flush flush); | ||||
|  | ||||
| /* tdefl_compress_buffer() is only usable when the tdefl_init() is called with a non-NULL tdefl_put_buf_func_ptr. */ | ||||
| /* tdefl_compress_buffer() always consumes the entire input buffer. */ | ||||
| tdefl_status tdefl_compress_buffer(tdefl_compressor *d, const void *pIn_buf, size_t in_buf_size, tdefl_flush flush); | ||||
| MINIZ_EXPORT tdefl_status tdefl_compress_buffer(tdefl_compressor *d, const void *pIn_buf, size_t in_buf_size, tdefl_flush flush); | ||||
|  | ||||
| tdefl_status tdefl_get_prev_return_status(tdefl_compressor *d); | ||||
| mz_uint32 tdefl_get_adler32(tdefl_compressor *d); | ||||
| MINIZ_EXPORT tdefl_status tdefl_get_prev_return_status(tdefl_compressor *d); | ||||
| MINIZ_EXPORT mz_uint32 tdefl_get_adler32(tdefl_compressor *d); | ||||
|  | ||||
| /* Create tdefl_compress() flags given zlib-style compression parameters. */ | ||||
| /* level may range from [0,10] (where 10 is absolute max compression, but may be much slower on some files) */ | ||||
| /* window_bits may be -15 (raw deflate) or 15 (zlib) */ | ||||
| /* strategy may be either MZ_DEFAULT_STRATEGY, MZ_FILTERED, MZ_HUFFMAN_ONLY, MZ_RLE, or MZ_FIXED */ | ||||
| mz_uint tdefl_create_comp_flags_from_zip_params(int level, int window_bits, int strategy); | ||||
| MINIZ_EXPORT mz_uint tdefl_create_comp_flags_from_zip_params(int level, int window_bits, int strategy); | ||||
|  | ||||
| #ifndef MINIZ_NO_MALLOC | ||||
| /* Allocate the tdefl_compressor structure in C so that */ | ||||
| /* non-C language bindings to tdefl_ API don't need to worry about */ | ||||
| /* structure size and allocation mechanism. */ | ||||
| tdefl_compressor *tdefl_compressor_alloc(); | ||||
| void tdefl_compressor_free(tdefl_compressor *pComp); | ||||
| MINIZ_EXPORT tdefl_compressor *tdefl_compressor_alloc(void); | ||||
| MINIZ_EXPORT void tdefl_compressor_free(tdefl_compressor *pComp); | ||||
| #endif | ||||
|  | ||||
| #ifdef __cplusplus | ||||
| } | ||||
|   | ||||
| @@ -24,7 +24,7 @@ | ||||
|  * | ||||
|  **************************************************************************/ | ||||
|  | ||||
| #include "miniz_tinfl.h" | ||||
| #include "miniz.h" | ||||
|  | ||||
| #ifdef __cplusplus | ||||
| extern "C" { | ||||
| @@ -498,7 +498,7 @@ tinfl_status tinfl_decompress(tinfl_decompressor *r, const mz_uint8 *pIn_buf_nex | ||||
|                 } | ||||
|  | ||||
|                 dist_from_out_buf_start = pOut_buf_cur - pOut_buf_start; | ||||
|                 if ((dist > dist_from_out_buf_start) && (decomp_flags & TINFL_FLAG_USING_NON_WRAPPING_OUTPUT_BUF)) | ||||
|                 if ((dist == 0 || dist > dist_from_out_buf_start || dist_from_out_buf_start == 0) && (decomp_flags & TINFL_FLAG_USING_NON_WRAPPING_OUTPUT_BUF)) | ||||
|                 { | ||||
|                     TINFL_CR_RETURN_FOREVER(37, TINFL_STATUS_FAILED); | ||||
|                 } | ||||
| @@ -523,8 +523,12 @@ tinfl_status tinfl_decompress(tinfl_decompressor *r, const mz_uint8 *pIn_buf_nex | ||||
|                     const mz_uint8 *pSrc_end = pSrc + (counter & ~7); | ||||
|                     do | ||||
|                     { | ||||
| #ifdef MINIZ_UNALIGNED_USE_MEMCPY | ||||
| 						memcpy(pOut_buf_cur, pSrc, sizeof(mz_uint32)*2); | ||||
| #else | ||||
|                         ((mz_uint32 *)pOut_buf_cur)[0] = ((const mz_uint32 *)pSrc)[0]; | ||||
|                         ((mz_uint32 *)pOut_buf_cur)[1] = ((const mz_uint32 *)pSrc)[1]; | ||||
| #endif | ||||
|                         pOut_buf_cur += 8; | ||||
|                     } while ((pSrc += 8) < pSrc_end); | ||||
|                     if ((counter &= 7) < 3) | ||||
| @@ -540,18 +544,19 @@ tinfl_status tinfl_decompress(tinfl_decompressor *r, const mz_uint8 *pIn_buf_nex | ||||
|                     } | ||||
|                 } | ||||
| #endif | ||||
|                 do | ||||
|                 while(counter>2) | ||||
|                 { | ||||
|                     pOut_buf_cur[0] = pSrc[0]; | ||||
|                     pOut_buf_cur[1] = pSrc[1]; | ||||
|                     pOut_buf_cur[2] = pSrc[2]; | ||||
|                     pOut_buf_cur += 3; | ||||
|                     pSrc += 3; | ||||
|                 } while ((int)(counter -= 3) > 2); | ||||
|                 if ((int)counter > 0) | ||||
| 					counter -= 3; | ||||
|                 } | ||||
|                 if (counter > 0) | ||||
|                 { | ||||
|                     pOut_buf_cur[0] = pSrc[0]; | ||||
|                     if ((int)counter > 1) | ||||
|                     if (counter > 1) | ||||
|                         pOut_buf_cur[1] = pSrc[1]; | ||||
|                     pOut_buf_cur += counter; | ||||
|                 } | ||||
| @@ -715,6 +720,7 @@ int tinfl_decompress_mem_to_callback(const void *pIn_buf, size_t *pIn_buf_size, | ||||
|     return result; | ||||
| } | ||||
|  | ||||
| #ifndef MINIZ_NO_MALLOC | ||||
| tinfl_decompressor *tinfl_decompressor_alloc() | ||||
| { | ||||
|     tinfl_decompressor *pDecomp = (tinfl_decompressor *)MZ_MALLOC(sizeof(tinfl_decompressor)); | ||||
| @@ -727,6 +733,7 @@ void tinfl_decompressor_free(tinfl_decompressor *pDecomp) | ||||
| { | ||||
|     MZ_FREE(pDecomp); | ||||
| } | ||||
| #endif | ||||
|  | ||||
| #ifdef __cplusplus | ||||
| } | ||||
|   | ||||
| @@ -26,27 +26,28 @@ enum | ||||
| /*  Function returns a pointer to the decompressed data, or NULL on failure. */ | ||||
| /*  *pOut_len will be set to the decompressed data's size, which could be larger than src_buf_len on uncompressible data. */ | ||||
| /*  The caller must call mz_free() on the returned block when it's no longer needed. */ | ||||
| void *tinfl_decompress_mem_to_heap(const void *pSrc_buf, size_t src_buf_len, size_t *pOut_len, int flags); | ||||
| MINIZ_EXPORT void *tinfl_decompress_mem_to_heap(const void *pSrc_buf, size_t src_buf_len, size_t *pOut_len, int flags); | ||||
|  | ||||
| /* tinfl_decompress_mem_to_mem() decompresses a block in memory to another block in memory. */ | ||||
| /* Returns TINFL_DECOMPRESS_MEM_TO_MEM_FAILED on failure, or the number of bytes written on success. */ | ||||
| #define TINFL_DECOMPRESS_MEM_TO_MEM_FAILED ((size_t)(-1)) | ||||
| size_t tinfl_decompress_mem_to_mem(void *pOut_buf, size_t out_buf_len, const void *pSrc_buf, size_t src_buf_len, int flags); | ||||
| MINIZ_EXPORT size_t tinfl_decompress_mem_to_mem(void *pOut_buf, size_t out_buf_len, const void *pSrc_buf, size_t src_buf_len, int flags); | ||||
|  | ||||
| /* tinfl_decompress_mem_to_callback() decompresses a block in memory to an internal 32KB buffer, and a user provided callback function will be called to flush the buffer. */ | ||||
| /* Returns 1 on success or 0 on failure. */ | ||||
| typedef int (*tinfl_put_buf_func_ptr)(const void *pBuf, int len, void *pUser); | ||||
| int tinfl_decompress_mem_to_callback(const void *pIn_buf, size_t *pIn_buf_size, tinfl_put_buf_func_ptr pPut_buf_func, void *pPut_buf_user, int flags); | ||||
| MINIZ_EXPORT int tinfl_decompress_mem_to_callback(const void *pIn_buf, size_t *pIn_buf_size, tinfl_put_buf_func_ptr pPut_buf_func, void *pPut_buf_user, int flags); | ||||
|  | ||||
| struct tinfl_decompressor_tag; | ||||
| typedef struct tinfl_decompressor_tag tinfl_decompressor; | ||||
|  | ||||
| #ifndef MINIZ_NO_MALLOC | ||||
| /* Allocate the tinfl_decompressor structure in C so that */ | ||||
| /* non-C language bindings to tinfl_ API don't need to worry about */ | ||||
| /* structure size and allocation mechanism. */ | ||||
|  | ||||
| tinfl_decompressor *tinfl_decompressor_alloc(); | ||||
| void tinfl_decompressor_free(tinfl_decompressor *pDecomp); | ||||
| MINIZ_EXPORT tinfl_decompressor *tinfl_decompressor_alloc(void); | ||||
| MINIZ_EXPORT void tinfl_decompressor_free(tinfl_decompressor *pDecomp); | ||||
| #endif | ||||
|  | ||||
| /* Max size of LZ dictionary. */ | ||||
| #define TINFL_LZ_DICT_SIZE 32768 | ||||
| @@ -96,7 +97,7 @@ typedef enum { | ||||
|  | ||||
| /* Main low-level decompressor coroutine function. This is the only function actually needed for decompression. All the other functions are just high-level helpers for improved usability. */ | ||||
| /* This is a universal API, i.e. it can be used as a building block to build any desired higher level decompression API. In the limit case, it can be called once per every byte input or output. */ | ||||
| tinfl_status tinfl_decompress(tinfl_decompressor *r, const mz_uint8 *pIn_buf_next, size_t *pIn_buf_size, mz_uint8 *pOut_buf_start, mz_uint8 *pOut_buf_next, size_t *pOut_buf_size, const mz_uint32 decomp_flags); | ||||
| MINIZ_EXPORT tinfl_status tinfl_decompress(tinfl_decompressor *r, const mz_uint8 *pIn_buf_next, size_t *pIn_buf_size, mz_uint8 *pOut_buf_start, mz_uint8 *pOut_buf_next, size_t *pOut_buf_size, const mz_uint32 decomp_flags); | ||||
|  | ||||
| /* Internal/private bits follow. */ | ||||
| enum | ||||
|   | ||||
							
								
								
									
										253
									
								
								miniz_zip.c
									
									
									
									
									
								
							
							
						
						
									
										253
									
								
								miniz_zip.c
									
									
									
									
									
								
							| @@ -24,7 +24,7 @@ | ||||
|  * THE SOFTWARE. | ||||
|  * | ||||
|  **************************************************************************/ | ||||
| #include "miniz_zip.h" | ||||
| #include "miniz.h" | ||||
|  | ||||
| #ifndef MINIZ_NO_ARCHIVE_APIS | ||||
|  | ||||
| @@ -62,8 +62,8 @@ static FILE *mz_freopen(const char *pPath, const char *pMode, FILE *pStream) | ||||
| #define MZ_FWRITE fwrite | ||||
| #define MZ_FTELL64 _ftelli64 | ||||
| #define MZ_FSEEK64 _fseeki64 | ||||
| #define MZ_FILE_STAT_STRUCT _stat | ||||
| #define MZ_FILE_STAT _stat | ||||
| #define MZ_FILE_STAT_STRUCT _stat64 | ||||
| #define MZ_FILE_STAT _stat64 | ||||
| #define MZ_FFLUSH fflush | ||||
| #define MZ_FREOPEN mz_freopen | ||||
| #define MZ_DELETE_FILE remove | ||||
| @@ -97,7 +97,7 @@ static FILE *mz_freopen(const char *pPath, const char *pMode, FILE *pStream) | ||||
| #define MZ_FFLUSH fflush | ||||
| #define MZ_FREOPEN(f, m, s) freopen(f, m, s) | ||||
| #define MZ_DELETE_FILE remove | ||||
| #elif defined(__GNUC__) && _LARGEFILE64_SOURCE | ||||
| #elif defined(__USE_LARGEFILE64) /* gcc, clang */ | ||||
| #ifndef MINIZ_NO_TIME | ||||
| #include <utime.h> | ||||
| #endif | ||||
| @@ -277,7 +277,7 @@ struct mz_zip_internal_state_tag | ||||
|  | ||||
| #define MZ_ZIP_ARRAY_SET_ELEMENT_SIZE(array_ptr, element_size) (array_ptr)->m_element_size = element_size | ||||
|  | ||||
| #if defined(DEBUG) || defined(_DEBUG) || defined(NDEBUG) | ||||
| #if defined(DEBUG) || defined(_DEBUG) | ||||
| static MZ_FORCEINLINE mz_uint mz_zip_array_range_check(const mz_zip_array *pArray, mz_uint index) | ||||
| { | ||||
|     MZ_ASSERT(index < pArray->m_size); | ||||
| @@ -351,7 +351,8 @@ static MZ_FORCEINLINE mz_bool mz_zip_array_push_back(mz_zip_archive *pZip, mz_zi | ||||
|     size_t orig_size = pArray->m_size; | ||||
|     if (!mz_zip_array_resize(pZip, pArray, orig_size + n, MZ_TRUE)) | ||||
|         return MZ_FALSE; | ||||
|     memcpy((mz_uint8 *)pArray->m_p + orig_size * pArray->m_element_size, pElements, n * pArray->m_element_size); | ||||
|     if (n > 0) | ||||
|         memcpy((mz_uint8 *)pArray->m_p + orig_size * pArray->m_element_size, pElements, n * pArray->m_element_size); | ||||
|     return MZ_TRUE; | ||||
| } | ||||
|  | ||||
| @@ -748,21 +749,47 @@ static mz_bool mz_zip_reader_read_central_dir(mz_zip_archive *pZip, mz_uint flag | ||||
|  | ||||
|                 if (extra_size_remaining) | ||||
|                 { | ||||
|                     const mz_uint8 *pExtra_data = p + MZ_ZIP_CENTRAL_DIR_HEADER_SIZE + filename_size; | ||||
| 					const mz_uint8 *pExtra_data; | ||||
| 					void* buf = NULL; | ||||
|  | ||||
| 					if (MZ_ZIP_CENTRAL_DIR_HEADER_SIZE + filename_size + ext_data_size > n) | ||||
| 					{ | ||||
| 						buf = MZ_MALLOC(ext_data_size); | ||||
| 						if(buf==NULL) | ||||
| 							return mz_zip_set_error(pZip, MZ_ZIP_ALLOC_FAILED); | ||||
|  | ||||
| 						if (pZip->m_pRead(pZip->m_pIO_opaque, cdir_ofs + MZ_ZIP_CENTRAL_DIR_HEADER_SIZE + filename_size, buf, ext_data_size) != ext_data_size) | ||||
| 						{ | ||||
| 							MZ_FREE(buf); | ||||
| 							return mz_zip_set_error(pZip, MZ_ZIP_FILE_READ_FAILED); | ||||
| 						} | ||||
|  | ||||
| 						pExtra_data = (mz_uint8*)buf; | ||||
| 					} | ||||
| 					else | ||||
| 					{ | ||||
| 						pExtra_data = p + MZ_ZIP_CENTRAL_DIR_HEADER_SIZE + filename_size; | ||||
| 					} | ||||
|  | ||||
|                     do | ||||
|                     { | ||||
|                         mz_uint32 field_id; | ||||
|                         mz_uint32 field_data_size; | ||||
|  | ||||
|                         if (extra_size_remaining < (sizeof(mz_uint16) * 2)) | ||||
|                             return mz_zip_set_error(pZip, MZ_ZIP_INVALID_HEADER_OR_CORRUPTED); | ||||
| 						if (extra_size_remaining < (sizeof(mz_uint16) * 2)) | ||||
| 						{ | ||||
| 							MZ_FREE(buf); | ||||
| 							return mz_zip_set_error(pZip, MZ_ZIP_INVALID_HEADER_OR_CORRUPTED); | ||||
| 						} | ||||
|  | ||||
|                         field_id = MZ_READ_LE16(pExtra_data); | ||||
|                         field_data_size = MZ_READ_LE16(pExtra_data + sizeof(mz_uint16)); | ||||
|  | ||||
|                         if ((field_data_size + sizeof(mz_uint16) * 2) > extra_size_remaining) | ||||
|                             return mz_zip_set_error(pZip, MZ_ZIP_INVALID_HEADER_OR_CORRUPTED); | ||||
| 						if ((field_data_size + sizeof(mz_uint16) * 2) > extra_size_remaining) | ||||
| 						{ | ||||
| 							MZ_FREE(buf); | ||||
| 							return mz_zip_set_error(pZip, MZ_ZIP_INVALID_HEADER_OR_CORRUPTED); | ||||
| 						} | ||||
|  | ||||
|                         if (field_id == MZ_ZIP64_EXTENDED_INFORMATION_FIELD_HEADER_ID) | ||||
|                         { | ||||
| @@ -775,6 +802,8 @@ static mz_bool mz_zip_reader_read_central_dir(mz_zip_archive *pZip, mz_uint flag | ||||
|                         pExtra_data += sizeof(mz_uint16) * 2 + field_data_size; | ||||
|                         extra_size_remaining = extra_size_remaining - sizeof(mz_uint16) * 2 - field_data_size; | ||||
|                     } while (extra_size_remaining); | ||||
|  | ||||
| 					MZ_FREE(buf); | ||||
|                 } | ||||
|             } | ||||
|  | ||||
| @@ -1616,7 +1645,9 @@ void *mz_zip_reader_extract_file_to_heap(mz_zip_archive *pZip, const char *pFile | ||||
| mz_bool mz_zip_reader_extract_to_callback(mz_zip_archive *pZip, mz_uint file_index, mz_file_write_func pCallback, void *pOpaque, mz_uint flags) | ||||
| { | ||||
|     int status = TINFL_STATUS_DONE; | ||||
| #ifndef MINIZ_DISABLE_ZIP_READER_CRC32_CHECKS | ||||
|     mz_uint file_crc32 = MZ_CRC32_INIT; | ||||
| #endif | ||||
|     mz_uint64 read_buf_size, read_buf_ofs = 0, read_buf_avail, comp_remaining, out_buf_ofs = 0, cur_file_ofs; | ||||
|     mz_zip_archive_file_stat file_stat; | ||||
|     void *pRead_buf = NULL; | ||||
| @@ -1912,7 +1943,7 @@ mz_zip_reader_extract_iter_state* mz_zip_reader_extract_iter_new(mz_zip_archive | ||||
|         if (!((flags & MZ_ZIP_FLAG_COMPRESSED_DATA) || (!pState->file_stat.m_method))) | ||||
|         { | ||||
|             /* Decompression required, therefore intermediate read buffer required */ | ||||
|             pState->read_buf_size = MZ_MIN(pState->file_stat.m_comp_size, MZ_ZIP_MAX_IO_BUF_SIZE); | ||||
|             pState->read_buf_size = MZ_MIN(pState->file_stat.m_comp_size, (mz_uint64)MZ_ZIP_MAX_IO_BUF_SIZE); | ||||
|             if (NULL == (pState->pRead_buf = pZip->m_pAlloc(pZip->m_pAlloc_opaque, 1, (size_t)pState->read_buf_size))) | ||||
|             { | ||||
|                 mz_zip_set_error(pZip, MZ_ZIP_ALLOC_FAILED); | ||||
| @@ -1971,7 +2002,7 @@ size_t mz_zip_reader_extract_iter_read(mz_zip_reader_extract_iter_state* pState, | ||||
|     if ((pState->flags & MZ_ZIP_FLAG_COMPRESSED_DATA) || (!pState->file_stat.m_method)) | ||||
|     { | ||||
|         /* The file is stored or the caller has requested the compressed data, calc amount to return. */ | ||||
|         copied_to_caller = MZ_MIN( buf_size, pState->comp_remaining ); | ||||
|         copied_to_caller = (size_t)MZ_MIN( buf_size, pState->comp_remaining ); | ||||
|  | ||||
|         /* Zip is in memory....or requires reading from a file? */ | ||||
|         if (pState->pZip->m_pState->m_pMem) | ||||
| @@ -2270,7 +2301,10 @@ mz_bool mz_zip_validate_file(mz_zip_archive *pZip, mz_uint file_index, mz_uint f | ||||
|         return mz_zip_set_error(pZip, MZ_ZIP_INVALID_HEADER_OR_CORRUPTED); | ||||
|  | ||||
|     if (!mz_zip_array_resize(pZip, &file_data_array, MZ_MAX(local_header_filename_len, local_header_extra_len), MZ_FALSE)) | ||||
|         return mz_zip_set_error(pZip, MZ_ZIP_ALLOC_FAILED); | ||||
|     { | ||||
|         mz_zip_set_error(pZip, MZ_ZIP_ALLOC_FAILED); | ||||
|         goto handle_failure; | ||||
|     } | ||||
|  | ||||
|     if (local_header_filename_len) | ||||
|     { | ||||
| @@ -2304,14 +2338,20 @@ mz_bool mz_zip_validate_file(mz_zip_archive *pZip, mz_uint file_index, mz_uint f | ||||
|             mz_uint32 field_id, field_data_size, field_total_size; | ||||
|  | ||||
|             if (extra_size_remaining < (sizeof(mz_uint16) * 2)) | ||||
|                 return mz_zip_set_error(pZip, MZ_ZIP_INVALID_HEADER_OR_CORRUPTED); | ||||
|             { | ||||
|                 mz_zip_set_error(pZip, MZ_ZIP_INVALID_HEADER_OR_CORRUPTED); | ||||
|                 goto handle_failure; | ||||
|             } | ||||
|  | ||||
|             field_id = MZ_READ_LE16(pExtra_data); | ||||
|             field_data_size = MZ_READ_LE16(pExtra_data + sizeof(mz_uint16)); | ||||
|             field_total_size = field_data_size + sizeof(mz_uint16) * 2; | ||||
|  | ||||
|             if (field_total_size > extra_size_remaining) | ||||
|                 return mz_zip_set_error(pZip, MZ_ZIP_INVALID_HEADER_OR_CORRUPTED); | ||||
|             { | ||||
|                 mz_zip_set_error(pZip, MZ_ZIP_INVALID_HEADER_OR_CORRUPTED); | ||||
|                 goto handle_failure; | ||||
|             } | ||||
|  | ||||
|             if (field_id == MZ_ZIP64_EXTENDED_INFORMATION_FIELD_HEADER_ID) | ||||
|             { | ||||
| @@ -3048,7 +3088,7 @@ static mz_bool mz_zip_writer_add_to_central_dir(mz_zip_archive *pZip, const char | ||||
|     if (((mz_uint64)pState->m_central_dir.m_size + MZ_ZIP_CENTRAL_DIR_HEADER_SIZE + filename_size + extra_size + user_extra_data_len + comment_size) >= MZ_UINT32_MAX) | ||||
|         return mz_zip_set_error(pZip, MZ_ZIP_UNSUPPORTED_CDIR_SIZE); | ||||
|  | ||||
|     if (!mz_zip_writer_create_central_dir_header(pZip, central_dir_header, filename_size, extra_size + user_extra_data_len, comment_size, uncomp_size, comp_size, uncomp_crc32, method, bit_flags, dos_time, dos_date, local_header_ofs, ext_attributes)) | ||||
|     if (!mz_zip_writer_create_central_dir_header(pZip, central_dir_header, filename_size, (mz_uint16)(extra_size + user_extra_data_len), comment_size, uncomp_size, comp_size, uncomp_crc32, method, bit_flags, dos_time, dos_date, local_header_ofs, ext_attributes)) | ||||
|         return mz_zip_set_error(pZip, MZ_ZIP_INTERNAL_ERROR); | ||||
|  | ||||
|     if ((!mz_zip_array_push_back(pZip, &pState->m_central_dir, central_dir_header, MZ_ZIP_CENTRAL_DIR_HEADER_SIZE)) || | ||||
| @@ -3072,13 +3112,7 @@ static mz_bool mz_zip_writer_validate_archive_name(const char *pArchive_name) | ||||
|     if (*pArchive_name == '/') | ||||
|         return MZ_FALSE; | ||||
|  | ||||
|     while (*pArchive_name) | ||||
|     { | ||||
|         if ((*pArchive_name == '\\') || (*pArchive_name == ':')) | ||||
|             return MZ_FALSE; | ||||
|  | ||||
|         pArchive_name++; | ||||
|     } | ||||
|     /* Making sure the name does not contain drive letters or DOS style backward slashes is the responsibility of the program using miniz*/ | ||||
|  | ||||
|     return MZ_TRUE; | ||||
| } | ||||
| @@ -3186,6 +3220,17 @@ mz_bool mz_zip_writer_add_mem_ex_v2(mz_zip_archive *pZip, const char *pArchive_n | ||||
|     } | ||||
| #endif /* #ifndef MINIZ_NO_TIME */ | ||||
|  | ||||
| 	if (!(level_and_flags & MZ_ZIP_FLAG_COMPRESSED_DATA)) | ||||
| 	{ | ||||
| 		uncomp_crc32 = (mz_uint32)mz_crc32(MZ_CRC32_INIT, (const mz_uint8 *)pBuf, buf_size); | ||||
| 		uncomp_size = buf_size; | ||||
| 		if (uncomp_size <= 3) | ||||
| 		{ | ||||
| 			level = 0; | ||||
| 			store_data_uncompressed = MZ_TRUE; | ||||
| 		} | ||||
| 	} | ||||
|  | ||||
|     archive_name_size = strlen(pArchive_name); | ||||
|     if (archive_name_size > MZ_UINT16_MAX) | ||||
|         return mz_zip_set_error(pZip, MZ_ZIP_INVALID_FILENAME); | ||||
| @@ -3199,8 +3244,8 @@ mz_bool mz_zip_writer_add_mem_ex_v2(mz_zip_archive *pZip, const char *pArchive_n | ||||
|     if (!pState->m_zip64) | ||||
|     { | ||||
|         /* Bail early if the archive would obviously become too large */ | ||||
|         if ((pZip->m_archive_size + num_alignment_padding_bytes + MZ_ZIP_LOCAL_DIR_HEADER_SIZE + archive_name_size  | ||||
| 			+ MZ_ZIP_CENTRAL_DIR_HEADER_SIZE + archive_name_size + comment_size + user_extra_data_len +  | ||||
|         if ((pZip->m_archive_size + num_alignment_padding_bytes + MZ_ZIP_LOCAL_DIR_HEADER_SIZE + archive_name_size | ||||
| 			+ MZ_ZIP_CENTRAL_DIR_HEADER_SIZE + archive_name_size + comment_size + user_extra_data_len + | ||||
| 			pState->m_central_dir.m_size + MZ_ZIP_END_OF_CENTRAL_DIR_HEADER_SIZE + user_extra_data_central_len | ||||
| 			+ MZ_ZIP_DATA_DESCRIPTER_SIZE32) > 0xFFFFFFFF) | ||||
|         { | ||||
| @@ -3258,7 +3303,7 @@ mz_bool mz_zip_writer_add_mem_ex_v2(mz_zip_archive *pZip, const char *pArchive_n | ||||
|                                                                (uncomp_size >= MZ_UINT32_MAX) ? &comp_size : NULL, (local_dir_header_ofs >= MZ_UINT32_MAX) ? &local_dir_header_ofs : NULL); | ||||
|         } | ||||
|  | ||||
|         if (!mz_zip_writer_create_local_dir_header(pZip, local_dir_header, (mz_uint16)archive_name_size, extra_size + user_extra_data_len, 0, 0, 0, method, bit_flags, dos_time, dos_date)) | ||||
|         if (!mz_zip_writer_create_local_dir_header(pZip, local_dir_header, (mz_uint16)archive_name_size, (mz_uint16)(extra_size + user_extra_data_len), 0, 0, 0, method, bit_flags, dos_time, dos_date)) | ||||
|             return mz_zip_set_error(pZip, MZ_ZIP_INTERNAL_ERROR); | ||||
|  | ||||
|         if (pZip->m_pWrite(pZip->m_pIO_opaque, local_dir_header_ofs, local_dir_header, sizeof(local_dir_header)) != sizeof(local_dir_header)) | ||||
| @@ -3285,7 +3330,7 @@ mz_bool mz_zip_writer_add_mem_ex_v2(mz_zip_archive *pZip, const char *pArchive_n | ||||
|     { | ||||
|         if ((comp_size > MZ_UINT32_MAX) || (cur_archive_file_ofs > MZ_UINT32_MAX)) | ||||
|             return mz_zip_set_error(pZip, MZ_ZIP_ARCHIVE_TOO_LARGE); | ||||
|         if (!mz_zip_writer_create_local_dir_header(pZip, local_dir_header, (mz_uint16)archive_name_size, user_extra_data_len, 0, 0, 0, method, bit_flags, dos_time, dos_date)) | ||||
|         if (!mz_zip_writer_create_local_dir_header(pZip, local_dir_header, (mz_uint16)archive_name_size, (mz_uint16)user_extra_data_len, 0, 0, 0, method, bit_flags, dos_time, dos_date)) | ||||
|             return mz_zip_set_error(pZip, MZ_ZIP_INTERNAL_ERROR); | ||||
|  | ||||
|         if (pZip->m_pWrite(pZip->m_pIO_opaque, local_dir_header_ofs, local_dir_header, sizeof(local_dir_header)) != sizeof(local_dir_header)) | ||||
| @@ -3301,24 +3346,13 @@ mz_bool mz_zip_writer_add_mem_ex_v2(mz_zip_archive *pZip, const char *pArchive_n | ||||
|         cur_archive_file_ofs += archive_name_size; | ||||
|     } | ||||
|  | ||||
|     if (user_extra_data_len > 0) | ||||
|     { | ||||
|         if (pZip->m_pWrite(pZip->m_pIO_opaque, cur_archive_file_ofs, user_extra_data, user_extra_data_len) != user_extra_data_len) | ||||
|             return mz_zip_set_error(pZip, MZ_ZIP_FILE_WRITE_FAILED); | ||||
| 	if (user_extra_data_len > 0) | ||||
| 	{ | ||||
| 		if (pZip->m_pWrite(pZip->m_pIO_opaque, cur_archive_file_ofs, user_extra_data, user_extra_data_len) != user_extra_data_len) | ||||
| 			return mz_zip_set_error(pZip, MZ_ZIP_FILE_WRITE_FAILED); | ||||
|  | ||||
|         cur_archive_file_ofs += user_extra_data_len; | ||||
|     } | ||||
|  | ||||
|     if (!(level_and_flags & MZ_ZIP_FLAG_COMPRESSED_DATA)) | ||||
|     { | ||||
|         uncomp_crc32 = (mz_uint32)mz_crc32(MZ_CRC32_INIT, (const mz_uint8 *)pBuf, buf_size); | ||||
|         uncomp_size = buf_size; | ||||
|         if (uncomp_size <= 3) | ||||
|         { | ||||
|             level = 0; | ||||
|             store_data_uncompressed = MZ_TRUE; | ||||
|         } | ||||
|     } | ||||
| 		cur_archive_file_ofs += user_extra_data_len; | ||||
| 	} | ||||
|  | ||||
|     if (store_data_uncompressed) | ||||
|     { | ||||
| @@ -3389,7 +3423,7 @@ mz_bool mz_zip_writer_add_mem_ex_v2(mz_zip_archive *pZip, const char *pArchive_n | ||||
|                                                            (uncomp_size >= MZ_UINT32_MAX) ? &comp_size : NULL, (local_dir_header_ofs >= MZ_UINT32_MAX) ? &local_dir_header_ofs : NULL); | ||||
|     } | ||||
|  | ||||
|     if (!mz_zip_writer_add_to_central_dir(pZip, pArchive_name, (mz_uint16)archive_name_size, pExtra_data, extra_size, pComment, | ||||
|     if (!mz_zip_writer_add_to_central_dir(pZip, pArchive_name, (mz_uint16)archive_name_size, pExtra_data, (mz_uint16)extra_size, pComment, | ||||
|                                           comment_size, uncomp_size, comp_size, uncomp_crc32, method, bit_flags, dos_time, dos_date, local_dir_header_ofs, ext_attributes, | ||||
|                                           user_extra_data_central, user_extra_data_central_len)) | ||||
|         return MZ_FALSE; | ||||
| @@ -3400,20 +3434,20 @@ mz_bool mz_zip_writer_add_mem_ex_v2(mz_zip_archive *pZip, const char *pArchive_n | ||||
|     return MZ_TRUE; | ||||
| } | ||||
|  | ||||
| #ifndef MINIZ_NO_STDIO | ||||
| mz_bool mz_zip_writer_add_cfile(mz_zip_archive *pZip, const char *pArchive_name, MZ_FILE *pSrc_file, mz_uint64 size_to_add, const MZ_TIME_T *pFile_time, const void *pComment, mz_uint16 comment_size, mz_uint level_and_flags, | ||||
| mz_bool mz_zip_writer_add_read_buf_callback(mz_zip_archive *pZip, const char *pArchive_name, mz_file_read_func read_callback, void* callback_opaque, mz_uint64 max_size, const MZ_TIME_T *pFile_time, const void *pComment, mz_uint16 comment_size, mz_uint level_and_flags, | ||||
|                                 const char *user_extra_data, mz_uint user_extra_data_len, const char *user_extra_data_central, mz_uint user_extra_data_central_len) | ||||
| { | ||||
|     mz_uint16 gen_flags = MZ_ZIP_LDH_BIT_FLAG_HAS_LOCATOR; | ||||
|     mz_uint16 gen_flags = (level_and_flags & MZ_ZIP_FLAG_WRITE_HEADER_SET_SIZE) ? 0 : MZ_ZIP_LDH_BIT_FLAG_HAS_LOCATOR; | ||||
|     mz_uint uncomp_crc32 = MZ_CRC32_INIT, level, num_alignment_padding_bytes; | ||||
|     mz_uint16 method = 0, dos_time = 0, dos_date = 0, ext_attributes = 0; | ||||
|     mz_uint64 local_dir_header_ofs, cur_archive_file_ofs = pZip->m_archive_size, uncomp_size = size_to_add, comp_size = 0; | ||||
|     mz_uint64 local_dir_header_ofs, cur_archive_file_ofs = pZip->m_archive_size, uncomp_size = 0, comp_size = 0; | ||||
|     size_t archive_name_size; | ||||
|     mz_uint8 local_dir_header[MZ_ZIP_LOCAL_DIR_HEADER_SIZE]; | ||||
|     mz_uint8 *pExtra_data = NULL; | ||||
|     mz_uint32 extra_size = 0; | ||||
|     mz_uint8 extra_data[MZ_ZIP64_MAX_CENTRAL_EXTRA_FIELD_SIZE]; | ||||
|     mz_zip_internal_state *pState; | ||||
|     mz_uint64 file_ofs = 0, cur_archive_header_file_ofs; | ||||
|  | ||||
|     if (!(level_and_flags & MZ_ZIP_FLAG_ASCII_FILENAME)) | ||||
|         gen_flags |= MZ_ZIP_GENERAL_PURPOSE_BIT_FLAG_UTF8; | ||||
| @@ -3428,7 +3462,7 @@ mz_bool mz_zip_writer_add_cfile(mz_zip_archive *pZip, const char *pArchive_name, | ||||
|  | ||||
|     pState = pZip->m_pState; | ||||
|  | ||||
|     if ((!pState->m_zip64) && (uncomp_size > MZ_UINT32_MAX)) | ||||
|     if ((!pState->m_zip64) && (max_size > MZ_UINT32_MAX)) | ||||
|     { | ||||
|         /* Source file is too large for non-zip64 */ | ||||
|         /*return mz_zip_set_error(pZip, MZ_ZIP_ARCHIVE_TOO_LARGE); */ | ||||
| @@ -3469,7 +3503,7 @@ mz_bool mz_zip_writer_add_cfile(mz_zip_archive *pZip, const char *pArchive_name, | ||||
|     if (!pState->m_zip64) | ||||
|     { | ||||
|         /* Bail early if the archive would obviously become too large */ | ||||
|         if ((pZip->m_archive_size + num_alignment_padding_bytes + MZ_ZIP_LOCAL_DIR_HEADER_SIZE + archive_name_size + MZ_ZIP_CENTRAL_DIR_HEADER_SIZE  | ||||
|         if ((pZip->m_archive_size + num_alignment_padding_bytes + MZ_ZIP_LOCAL_DIR_HEADER_SIZE + archive_name_size + MZ_ZIP_CENTRAL_DIR_HEADER_SIZE | ||||
| 			+ archive_name_size + comment_size + user_extra_data_len + pState->m_central_dir.m_size + MZ_ZIP_END_OF_CENTRAL_DIR_HEADER_SIZE + 1024 | ||||
| 			+ MZ_ZIP_DATA_DESCRIPTER_SIZE32 + user_extra_data_central_len) > 0xFFFFFFFF) | ||||
|         { | ||||
| @@ -3485,7 +3519,7 @@ mz_bool mz_zip_writer_add_cfile(mz_zip_archive *pZip, const char *pArchive_name, | ||||
|     } | ||||
| #endif | ||||
|  | ||||
|     if (uncomp_size <= 3) | ||||
|     if (max_size <= 3) | ||||
|         level = 0; | ||||
|  | ||||
|     if (!mz_zip_writer_write_zeros(pZip, cur_archive_file_ofs, num_alignment_padding_bytes)) | ||||
| @@ -3501,7 +3535,7 @@ mz_bool mz_zip_writer_add_cfile(mz_zip_archive *pZip, const char *pArchive_name, | ||||
|         MZ_ASSERT((cur_archive_file_ofs & (pZip->m_file_offset_alignment - 1)) == 0); | ||||
|     } | ||||
|  | ||||
|     if (uncomp_size && level) | ||||
|     if (max_size && level) | ||||
|     { | ||||
|         method = MZ_DEFLATED; | ||||
|     } | ||||
| @@ -3509,14 +3543,20 @@ mz_bool mz_zip_writer_add_cfile(mz_zip_archive *pZip, const char *pArchive_name, | ||||
|     MZ_CLEAR_OBJ(local_dir_header); | ||||
|     if (pState->m_zip64) | ||||
|     { | ||||
|         if (uncomp_size >= MZ_UINT32_MAX || local_dir_header_ofs >= MZ_UINT32_MAX) | ||||
|         if (max_size >= MZ_UINT32_MAX || local_dir_header_ofs >= MZ_UINT32_MAX) | ||||
|         { | ||||
|             pExtra_data = extra_data; | ||||
|             extra_size = mz_zip_writer_create_zip64_extra_data(extra_data, (uncomp_size >= MZ_UINT32_MAX) ? &uncomp_size : NULL, | ||||
|                                                                (uncomp_size >= MZ_UINT32_MAX) ? &comp_size : NULL, (local_dir_header_ofs >= MZ_UINT32_MAX) ? &local_dir_header_ofs : NULL); | ||||
|             if (level_and_flags & MZ_ZIP_FLAG_WRITE_HEADER_SET_SIZE) | ||||
|                 extra_size = mz_zip_writer_create_zip64_extra_data(extra_data, (max_size >= MZ_UINT32_MAX) ? &uncomp_size : NULL, | ||||
|                                                                (max_size >= MZ_UINT32_MAX) ? &comp_size : NULL, | ||||
|                                                                 (local_dir_header_ofs >= MZ_UINT32_MAX) ? &local_dir_header_ofs : NULL); | ||||
|             else | ||||
|                 extra_size = mz_zip_writer_create_zip64_extra_data(extra_data, NULL, | ||||
|                                                                    NULL, | ||||
|                                                                    (local_dir_header_ofs >= MZ_UINT32_MAX) ? &local_dir_header_ofs : NULL); | ||||
|         } | ||||
|  | ||||
|         if (!mz_zip_writer_create_local_dir_header(pZip, local_dir_header, (mz_uint16)archive_name_size, extra_size + user_extra_data_len, 0, 0, 0, method, gen_flags, dos_time, dos_date)) | ||||
|         if (!mz_zip_writer_create_local_dir_header(pZip, local_dir_header, (mz_uint16)archive_name_size, (mz_uint16)(extra_size + user_extra_data_len), 0, 0, 0, method, gen_flags, dos_time, dos_date)) | ||||
|             return mz_zip_set_error(pZip, MZ_ZIP_INTERNAL_ERROR); | ||||
|  | ||||
|         if (pZip->m_pWrite(pZip->m_pIO_opaque, cur_archive_file_ofs, local_dir_header, sizeof(local_dir_header)) != sizeof(local_dir_header)) | ||||
| @@ -3540,7 +3580,7 @@ mz_bool mz_zip_writer_add_cfile(mz_zip_archive *pZip, const char *pArchive_name, | ||||
|     { | ||||
|         if ((comp_size > MZ_UINT32_MAX) || (cur_archive_file_ofs > MZ_UINT32_MAX)) | ||||
|             return mz_zip_set_error(pZip, MZ_ZIP_ARCHIVE_TOO_LARGE); | ||||
|         if (!mz_zip_writer_create_local_dir_header(pZip, local_dir_header, (mz_uint16)archive_name_size, user_extra_data_len, 0, 0, 0, method, gen_flags, dos_time, dos_date)) | ||||
|         if (!mz_zip_writer_create_local_dir_header(pZip, local_dir_header, (mz_uint16)archive_name_size, (mz_uint16)user_extra_data_len, 0, 0, 0, method, gen_flags, dos_time, dos_date)) | ||||
|             return mz_zip_set_error(pZip, MZ_ZIP_INTERNAL_ERROR); | ||||
|  | ||||
|         if (pZip->m_pWrite(pZip->m_pIO_opaque, cur_archive_file_ofs, local_dir_header, sizeof(local_dir_header)) != sizeof(local_dir_header)) | ||||
| @@ -3564,9 +3604,8 @@ mz_bool mz_zip_writer_add_cfile(mz_zip_archive *pZip, const char *pArchive_name, | ||||
|         cur_archive_file_ofs += user_extra_data_len; | ||||
|     } | ||||
|  | ||||
|     if (uncomp_size) | ||||
|     if (max_size) | ||||
|     { | ||||
|         mz_uint64 uncomp_remaining = uncomp_size; | ||||
|         void *pRead_buf = pZip->m_pAlloc(pZip->m_pAlloc_opaque, 1, MZ_ZIP_MAX_IO_BUF_SIZE); | ||||
|         if (!pRead_buf) | ||||
|         { | ||||
| @@ -3575,18 +3614,27 @@ mz_bool mz_zip_writer_add_cfile(mz_zip_archive *pZip, const char *pArchive_name, | ||||
|  | ||||
|         if (!level) | ||||
|         { | ||||
|             while (uncomp_remaining) | ||||
|             while (1) | ||||
|             { | ||||
|                 mz_uint n = (mz_uint)MZ_MIN((mz_uint64)MZ_ZIP_MAX_IO_BUF_SIZE, uncomp_remaining); | ||||
|                 if ((MZ_FREAD(pRead_buf, 1, n, pSrc_file) != n) || (pZip->m_pWrite(pZip->m_pIO_opaque, cur_archive_file_ofs, pRead_buf, n) != n)) | ||||
|                 size_t n = read_callback(callback_opaque, file_ofs, pRead_buf, MZ_ZIP_MAX_IO_BUF_SIZE); | ||||
|                 if (n == 0) | ||||
|                     break; | ||||
|  | ||||
|                 if ((n > MZ_ZIP_MAX_IO_BUF_SIZE) || (file_ofs + n > max_size)) | ||||
|                 { | ||||
|                     pZip->m_pFree(pZip->m_pAlloc_opaque, pRead_buf); | ||||
|                     return mz_zip_set_error(pZip, MZ_ZIP_FILE_READ_FAILED); | ||||
|                 } | ||||
|                 if (pZip->m_pWrite(pZip->m_pIO_opaque, cur_archive_file_ofs, pRead_buf, n) != n) | ||||
|                 { | ||||
|                     pZip->m_pFree(pZip->m_pAlloc_opaque, pRead_buf); | ||||
|                     return mz_zip_set_error(pZip, MZ_ZIP_FILE_WRITE_FAILED); | ||||
|                 } | ||||
|                 file_ofs += n; | ||||
|                 uncomp_crc32 = (mz_uint32)mz_crc32(uncomp_crc32, (const mz_uint8 *)pRead_buf, n); | ||||
|                 uncomp_remaining -= n; | ||||
|                 cur_archive_file_ofs += n; | ||||
|             } | ||||
|             uncomp_size = file_ofs; | ||||
|             comp_size = uncomp_size; | ||||
|         } | ||||
|         else | ||||
| @@ -3613,23 +3661,26 @@ mz_bool mz_zip_writer_add_cfile(mz_zip_archive *pZip, const char *pArchive_name, | ||||
|  | ||||
|             for (;;) | ||||
|             { | ||||
|                 size_t in_buf_size = (mz_uint32)MZ_MIN(uncomp_remaining, (mz_uint64)MZ_ZIP_MAX_IO_BUF_SIZE); | ||||
|                 tdefl_status status; | ||||
|                 tdefl_flush flush = TDEFL_NO_FLUSH; | ||||
|  | ||||
|                 if (MZ_FREAD(pRead_buf, 1, in_buf_size, pSrc_file) != in_buf_size) | ||||
|                 size_t n = read_callback(callback_opaque, file_ofs, pRead_buf, MZ_ZIP_MAX_IO_BUF_SIZE); | ||||
|                 if ((n > MZ_ZIP_MAX_IO_BUF_SIZE) || (file_ofs + n > max_size)) | ||||
|                 { | ||||
|                     mz_zip_set_error(pZip, MZ_ZIP_FILE_READ_FAILED); | ||||
|                     break; | ||||
|                 } | ||||
|  | ||||
|                 uncomp_crc32 = (mz_uint32)mz_crc32(uncomp_crc32, (const mz_uint8 *)pRead_buf, in_buf_size); | ||||
|                 uncomp_remaining -= in_buf_size; | ||||
|                 file_ofs += n; | ||||
|                 uncomp_crc32 = (mz_uint32)mz_crc32(uncomp_crc32, (const mz_uint8 *)pRead_buf, n); | ||||
|  | ||||
|                 if (pZip->m_pNeeds_keepalive != NULL && pZip->m_pNeeds_keepalive(pZip->m_pIO_opaque)) | ||||
|                     flush = TDEFL_FULL_FLUSH; | ||||
|  | ||||
|                 status = tdefl_compress_buffer(pComp, pRead_buf, in_buf_size, uncomp_remaining ? flush : TDEFL_FINISH); | ||||
|                 if (n == 0) | ||||
|                     flush = TDEFL_FINISH; | ||||
|  | ||||
|                 status = tdefl_compress_buffer(pComp, pRead_buf, n, flush); | ||||
|                 if (status == TDEFL_STATUS_DONE) | ||||
|                 { | ||||
|                     result = MZ_TRUE; | ||||
| @@ -3650,6 +3701,7 @@ mz_bool mz_zip_writer_add_cfile(mz_zip_archive *pZip, const char *pArchive_name, | ||||
|                 return MZ_FALSE; | ||||
|             } | ||||
|  | ||||
|             uncomp_size = file_ofs; | ||||
|             comp_size = state.m_comp_size; | ||||
|             cur_archive_file_ofs = state.m_cur_archive_file_ofs; | ||||
|         } | ||||
| @@ -3657,6 +3709,7 @@ mz_bool mz_zip_writer_add_cfile(mz_zip_archive *pZip, const char *pArchive_name, | ||||
|         pZip->m_pFree(pZip->m_pAlloc_opaque, pRead_buf); | ||||
|     } | ||||
|  | ||||
|     if (!(level_and_flags & MZ_ZIP_FLAG_WRITE_HEADER_SET_SIZE)) | ||||
|     { | ||||
|         mz_uint8 local_dir_footer[MZ_ZIP_DATA_DESCRIPTER_SIZE64]; | ||||
|         mz_uint32 local_dir_footer_size = MZ_ZIP_DATA_DESCRIPTER_SIZE32; | ||||
| @@ -3684,13 +3737,51 @@ mz_bool mz_zip_writer_add_cfile(mz_zip_archive *pZip, const char *pArchive_name, | ||||
|         cur_archive_file_ofs += local_dir_footer_size; | ||||
|     } | ||||
|  | ||||
|     if (level_and_flags & MZ_ZIP_FLAG_WRITE_HEADER_SET_SIZE) | ||||
|     { | ||||
|         if (pExtra_data != NULL) | ||||
|         { | ||||
|             extra_size = mz_zip_writer_create_zip64_extra_data(extra_data, (max_size >= MZ_UINT32_MAX) ? &uncomp_size : NULL, | ||||
|                                                                (max_size >= MZ_UINT32_MAX) ? &comp_size : NULL, (local_dir_header_ofs >= MZ_UINT32_MAX) ? &local_dir_header_ofs : NULL); | ||||
|         } | ||||
|  | ||||
|         if (!mz_zip_writer_create_local_dir_header(pZip, local_dir_header, | ||||
|                                                    (mz_uint16)archive_name_size, (mz_uint16)(extra_size + user_extra_data_len), | ||||
|                                                    (max_size >= MZ_UINT32_MAX) ? MZ_UINT32_MAX : uncomp_size,  | ||||
|                                                     (max_size >= MZ_UINT32_MAX) ? MZ_UINT32_MAX : comp_size, | ||||
|                                                    uncomp_crc32, method, gen_flags, dos_time, dos_date)) | ||||
|             return mz_zip_set_error(pZip, MZ_ZIP_INTERNAL_ERROR); | ||||
|  | ||||
|         cur_archive_header_file_ofs = local_dir_header_ofs; | ||||
|  | ||||
|         if (pZip->m_pWrite(pZip->m_pIO_opaque, cur_archive_header_file_ofs, local_dir_header, sizeof(local_dir_header)) != sizeof(local_dir_header)) | ||||
|             return mz_zip_set_error(pZip, MZ_ZIP_FILE_WRITE_FAILED); | ||||
|  | ||||
|         if (pExtra_data != NULL) | ||||
|         { | ||||
|             cur_archive_header_file_ofs += sizeof(local_dir_header); | ||||
|  | ||||
|             if (pZip->m_pWrite(pZip->m_pIO_opaque, cur_archive_header_file_ofs, pArchive_name, archive_name_size) != archive_name_size) | ||||
|             { | ||||
|                 return mz_zip_set_error(pZip, MZ_ZIP_FILE_WRITE_FAILED); | ||||
|             } | ||||
|  | ||||
|             cur_archive_header_file_ofs += archive_name_size; | ||||
|  | ||||
|             if (pZip->m_pWrite(pZip->m_pIO_opaque, cur_archive_header_file_ofs, extra_data, extra_size) != extra_size) | ||||
|                 return mz_zip_set_error(pZip, MZ_ZIP_FILE_WRITE_FAILED); | ||||
|  | ||||
|             cur_archive_header_file_ofs += extra_size; | ||||
|         } | ||||
|     } | ||||
|  | ||||
|     if (pExtra_data != NULL) | ||||
|     { | ||||
|         extra_size = mz_zip_writer_create_zip64_extra_data(extra_data, (uncomp_size >= MZ_UINT32_MAX) ? &uncomp_size : NULL, | ||||
|                                                            (uncomp_size >= MZ_UINT32_MAX) ? &comp_size : NULL, (local_dir_header_ofs >= MZ_UINT32_MAX) ? &local_dir_header_ofs : NULL); | ||||
|     } | ||||
|  | ||||
|     if (!mz_zip_writer_add_to_central_dir(pZip, pArchive_name, (mz_uint16)archive_name_size, pExtra_data, extra_size, pComment, comment_size, | ||||
|     if (!mz_zip_writer_add_to_central_dir(pZip, pArchive_name, (mz_uint16)archive_name_size, pExtra_data, (mz_uint16)extra_size, pComment, comment_size, | ||||
|                                           uncomp_size, comp_size, uncomp_crc32, method, gen_flags, dos_time, dos_date, local_dir_header_ofs, ext_attributes, | ||||
|                                           user_extra_data_central, user_extra_data_central_len)) | ||||
|         return MZ_FALSE; | ||||
| @@ -3701,6 +3792,26 @@ mz_bool mz_zip_writer_add_cfile(mz_zip_archive *pZip, const char *pArchive_name, | ||||
|     return MZ_TRUE; | ||||
| } | ||||
|  | ||||
| #ifndef MINIZ_NO_STDIO | ||||
|  | ||||
| static size_t mz_file_read_func_stdio(void *pOpaque, mz_uint64 file_ofs, void *pBuf, size_t n) | ||||
| { | ||||
| 	MZ_FILE *pSrc_file = (MZ_FILE *)pOpaque; | ||||
| 	mz_int64 cur_ofs = MZ_FTELL64(pSrc_file); | ||||
|  | ||||
| 	if (((mz_int64)file_ofs < 0) || (((cur_ofs != (mz_int64)file_ofs)) && (MZ_FSEEK64(pSrc_file, (mz_int64)file_ofs, SEEK_SET)))) | ||||
| 		return 0; | ||||
|  | ||||
| 	return MZ_FREAD(pBuf, 1, n, pSrc_file); | ||||
| } | ||||
|  | ||||
| mz_bool mz_zip_writer_add_cfile(mz_zip_archive *pZip, const char *pArchive_name, MZ_FILE *pSrc_file, mz_uint64 max_size, const MZ_TIME_T *pFile_time, const void *pComment, mz_uint16 comment_size, mz_uint level_and_flags, | ||||
| 	const char *user_extra_data, mz_uint user_extra_data_len, const char *user_extra_data_central, mz_uint user_extra_data_central_len) | ||||
| { | ||||
| 	return mz_zip_writer_add_read_buf_callback(pZip, pArchive_name, mz_file_read_func_stdio, pSrc_file, max_size, pFile_time, pComment, comment_size, level_and_flags, | ||||
| 		user_extra_data, user_extra_data_len, user_extra_data_central, user_extra_data_central_len); | ||||
| } | ||||
|  | ||||
| mz_bool mz_zip_writer_add_file(mz_zip_archive *pZip, const char *pArchive_name, const char *pSrc_filename, const void *pComment, mz_uint16 comment_size, mz_uint level_and_flags) | ||||
| { | ||||
|     MZ_FILE *pSrc_file = NULL; | ||||
|   | ||||
							
								
								
									
										171
									
								
								miniz_zip.h
									
									
									
									
									
								
							
							
						
						
									
										171
									
								
								miniz_zip.h
									
									
									
									
									
								
							| @@ -1,6 +1,6 @@ | ||||
|  | ||||
| #pragma once | ||||
| #include "miniz.h" | ||||
| #include "miniz_common.h" | ||||
|  | ||||
| /* ------------------- ZIP archive reading/writing */ | ||||
|  | ||||
| @@ -97,7 +97,10 @@ typedef enum { | ||||
|     MZ_ZIP_FLAG_VALIDATE_HEADERS_ONLY = 0x2000,     /* validate the local headers, but don't decompress the entire file and check the crc32 */ | ||||
|     MZ_ZIP_FLAG_WRITE_ZIP64 = 0x4000,               /* always use the zip64 file format, instead of the original zip file format with automatic switch to zip64. Use as flags parameter with mz_zip_writer_init*_v2 */ | ||||
|     MZ_ZIP_FLAG_WRITE_ALLOW_READING = 0x8000, | ||||
|     MZ_ZIP_FLAG_ASCII_FILENAME = 0x10000 | ||||
|     MZ_ZIP_FLAG_ASCII_FILENAME = 0x10000, | ||||
|     /*After adding a compressed file, seek back | ||||
|     to local file header and set the correct sizes*/ | ||||
|     MZ_ZIP_FLAG_WRITE_HEADER_SET_SIZE = 0x20000 | ||||
| } mz_zip_flags; | ||||
|  | ||||
| typedef enum { | ||||
| @@ -198,124 +201,117 @@ typedef struct | ||||
|  | ||||
| /* Inits a ZIP archive reader. */ | ||||
| /* These functions read and validate the archive's central directory. */ | ||||
| mz_bool mz_zip_reader_init(mz_zip_archive *pZip, mz_uint64 size, mz_uint flags); | ||||
| MINIZ_EXPORT mz_bool mz_zip_reader_init(mz_zip_archive *pZip, mz_uint64 size, mz_uint flags); | ||||
|  | ||||
| mz_bool mz_zip_reader_init_mem(mz_zip_archive *pZip, const void *pMem, size_t size, mz_uint flags); | ||||
| MINIZ_EXPORT mz_bool mz_zip_reader_init_mem(mz_zip_archive *pZip, const void *pMem, size_t size, mz_uint flags); | ||||
|  | ||||
| #ifndef MINIZ_NO_STDIO | ||||
| /* Read a archive from a disk file. */ | ||||
| /* file_start_ofs is the file offset where the archive actually begins, or 0. */ | ||||
| /* actual_archive_size is the true total size of the archive, which may be smaller than the file's actual size on disk. If zero the entire file is treated as the archive. */ | ||||
| mz_bool mz_zip_reader_init_file(mz_zip_archive *pZip, const char *pFilename, mz_uint32 flags); | ||||
| mz_bool mz_zip_reader_init_file_v2(mz_zip_archive *pZip, const char *pFilename, mz_uint flags, mz_uint64 file_start_ofs, mz_uint64 archive_size); | ||||
| MINIZ_EXPORT mz_bool mz_zip_reader_init_file(mz_zip_archive *pZip, const char *pFilename, mz_uint32 flags); | ||||
| MINIZ_EXPORT mz_bool mz_zip_reader_init_file_v2(mz_zip_archive *pZip, const char *pFilename, mz_uint flags, mz_uint64 file_start_ofs, mz_uint64 archive_size); | ||||
|  | ||||
| /* Read an archive from an already opened FILE, beginning at the current file position. */ | ||||
| /* The archive is assumed to be archive_size bytes long. If archive_size is < 0, then the entire rest of the file is assumed to contain the archive. */ | ||||
| /* The archive is assumed to be archive_size bytes long. If archive_size is 0, then the entire rest of the file is assumed to contain the archive. */ | ||||
| /* The FILE will NOT be closed when mz_zip_reader_end() is called. */ | ||||
| mz_bool mz_zip_reader_init_cfile(mz_zip_archive *pZip, MZ_FILE *pFile, mz_uint64 archive_size, mz_uint flags); | ||||
| MINIZ_EXPORT mz_bool mz_zip_reader_init_cfile(mz_zip_archive *pZip, MZ_FILE *pFile, mz_uint64 archive_size, mz_uint flags); | ||||
| #endif | ||||
|  | ||||
| /* Ends archive reading, freeing all allocations, and closing the input archive file if mz_zip_reader_init_file() was used. */ | ||||
| mz_bool mz_zip_reader_end(mz_zip_archive *pZip); | ||||
| MINIZ_EXPORT mz_bool mz_zip_reader_end(mz_zip_archive *pZip); | ||||
|  | ||||
| /* -------- ZIP reading or writing */ | ||||
|  | ||||
| /* Clears a mz_zip_archive struct to all zeros. */ | ||||
| /* Important: This must be done before passing the struct to any mz_zip functions. */ | ||||
| void mz_zip_zero_struct(mz_zip_archive *pZip); | ||||
| MINIZ_EXPORT void mz_zip_zero_struct(mz_zip_archive *pZip); | ||||
|  | ||||
| mz_zip_mode mz_zip_get_mode(mz_zip_archive *pZip); | ||||
| mz_zip_type mz_zip_get_type(mz_zip_archive *pZip); | ||||
| MINIZ_EXPORT mz_zip_mode mz_zip_get_mode(mz_zip_archive *pZip); | ||||
| MINIZ_EXPORT mz_zip_type mz_zip_get_type(mz_zip_archive *pZip); | ||||
|  | ||||
| /* Returns the total number of files in the archive. */ | ||||
| mz_uint mz_zip_reader_get_num_files(mz_zip_archive *pZip); | ||||
| MINIZ_EXPORT mz_uint mz_zip_reader_get_num_files(mz_zip_archive *pZip); | ||||
|  | ||||
| mz_uint64 mz_zip_get_archive_size(mz_zip_archive *pZip); | ||||
| mz_uint64 mz_zip_get_archive_file_start_offset(mz_zip_archive *pZip); | ||||
| MZ_FILE *mz_zip_get_cfile(mz_zip_archive *pZip); | ||||
| MINIZ_EXPORT mz_uint64 mz_zip_get_archive_size(mz_zip_archive *pZip); | ||||
| MINIZ_EXPORT mz_uint64 mz_zip_get_archive_file_start_offset(mz_zip_archive *pZip); | ||||
| MINIZ_EXPORT MZ_FILE *mz_zip_get_cfile(mz_zip_archive *pZip); | ||||
|  | ||||
| /* Reads n bytes of raw archive data, starting at file offset file_ofs, to pBuf. */ | ||||
| size_t mz_zip_read_archive_data(mz_zip_archive *pZip, mz_uint64 file_ofs, void *pBuf, size_t n); | ||||
|  | ||||
| /* Attempts to locates a file in the archive's central directory. */ | ||||
| /* Valid flags: MZ_ZIP_FLAG_CASE_SENSITIVE, MZ_ZIP_FLAG_IGNORE_PATH */ | ||||
| /* Returns -1 if the file cannot be found. */ | ||||
| int mz_zip_locate_file(mz_zip_archive *pZip, const char *pName, const char *pComment, mz_uint flags); | ||||
| /* Returns MZ_FALSE if the file cannot be found. */ | ||||
| mz_bool mz_zip_locate_file_v2(mz_zip_archive *pZip, const char *pName, const char *pComment, mz_uint flags, mz_uint32 *pIndex); | ||||
| MINIZ_EXPORT size_t mz_zip_read_archive_data(mz_zip_archive *pZip, mz_uint64 file_ofs, void *pBuf, size_t n); | ||||
|  | ||||
| /* All mz_zip funcs set the m_last_error field in the mz_zip_archive struct. These functions retrieve/manipulate this field. */ | ||||
| /* Note that the m_last_error functionality is not thread safe. */ | ||||
| mz_zip_error mz_zip_set_last_error(mz_zip_archive *pZip, mz_zip_error err_num); | ||||
| mz_zip_error mz_zip_peek_last_error(mz_zip_archive *pZip); | ||||
| mz_zip_error mz_zip_clear_last_error(mz_zip_archive *pZip); | ||||
| mz_zip_error mz_zip_get_last_error(mz_zip_archive *pZip); | ||||
| const char *mz_zip_get_error_string(mz_zip_error mz_err); | ||||
| MINIZ_EXPORT mz_zip_error mz_zip_set_last_error(mz_zip_archive *pZip, mz_zip_error err_num); | ||||
| MINIZ_EXPORT mz_zip_error mz_zip_peek_last_error(mz_zip_archive *pZip); | ||||
| MINIZ_EXPORT mz_zip_error mz_zip_clear_last_error(mz_zip_archive *pZip); | ||||
| MINIZ_EXPORT mz_zip_error mz_zip_get_last_error(mz_zip_archive *pZip); | ||||
| MINIZ_EXPORT const char *mz_zip_get_error_string(mz_zip_error mz_err); | ||||
|  | ||||
| /* MZ_TRUE if the archive file entry is a directory entry. */ | ||||
| mz_bool mz_zip_reader_is_file_a_directory(mz_zip_archive *pZip, mz_uint file_index); | ||||
| MINIZ_EXPORT mz_bool mz_zip_reader_is_file_a_directory(mz_zip_archive *pZip, mz_uint file_index); | ||||
|  | ||||
| /* MZ_TRUE if the file is encrypted/strong encrypted. */ | ||||
| mz_bool mz_zip_reader_is_file_encrypted(mz_zip_archive *pZip, mz_uint file_index); | ||||
| MINIZ_EXPORT mz_bool mz_zip_reader_is_file_encrypted(mz_zip_archive *pZip, mz_uint file_index); | ||||
|  | ||||
| /* MZ_TRUE if the compression method is supported, and the file is not encrypted, and the file is not a compressed patch file. */ | ||||
| mz_bool mz_zip_reader_is_file_supported(mz_zip_archive *pZip, mz_uint file_index); | ||||
| MINIZ_EXPORT mz_bool mz_zip_reader_is_file_supported(mz_zip_archive *pZip, mz_uint file_index); | ||||
|  | ||||
| /* Retrieves the filename of an archive file entry. */ | ||||
| /* Returns the number of bytes written to pFilename, or if filename_buf_size is 0 this function returns the number of bytes needed to fully store the filename. */ | ||||
| mz_uint mz_zip_reader_get_filename(mz_zip_archive *pZip, mz_uint file_index, char *pFilename, mz_uint filename_buf_size); | ||||
| MINIZ_EXPORT mz_uint mz_zip_reader_get_filename(mz_zip_archive *pZip, mz_uint file_index, char *pFilename, mz_uint filename_buf_size); | ||||
|  | ||||
| /* Attempts to locates a file in the archive's central directory. */ | ||||
| /* Valid flags: MZ_ZIP_FLAG_CASE_SENSITIVE, MZ_ZIP_FLAG_IGNORE_PATH */ | ||||
| /* Returns -1 if the file cannot be found. */ | ||||
| int mz_zip_reader_locate_file(mz_zip_archive *pZip, const char *pName, const char *pComment, mz_uint flags); | ||||
| int mz_zip_reader_locate_file_v2(mz_zip_archive *pZip, const char *pName, const char *pComment, mz_uint flags, mz_uint32 *file_index); | ||||
| MINIZ_EXPORT int mz_zip_reader_locate_file(mz_zip_archive *pZip, const char *pName, const char *pComment, mz_uint flags); | ||||
| MINIZ_EXPORT mz_bool mz_zip_reader_locate_file_v2(mz_zip_archive *pZip, const char *pName, const char *pComment, mz_uint flags, mz_uint32 *file_index); | ||||
|  | ||||
| /* Returns detailed information about an archive file entry. */ | ||||
| mz_bool mz_zip_reader_file_stat(mz_zip_archive *pZip, mz_uint file_index, mz_zip_archive_file_stat *pStat); | ||||
| MINIZ_EXPORT mz_bool mz_zip_reader_file_stat(mz_zip_archive *pZip, mz_uint file_index, mz_zip_archive_file_stat *pStat); | ||||
|  | ||||
| /* MZ_TRUE if the file is in zip64 format. */ | ||||
| /* A file is considered zip64 if it contained a zip64 end of central directory marker, or if it contained any zip64 extended file information fields in the central directory. */ | ||||
| mz_bool mz_zip_is_zip64(mz_zip_archive *pZip); | ||||
| MINIZ_EXPORT mz_bool mz_zip_is_zip64(mz_zip_archive *pZip); | ||||
|  | ||||
| /* Returns the total central directory size in bytes. */ | ||||
| /* The current max supported size is <= MZ_UINT32_MAX. */ | ||||
| size_t mz_zip_get_central_dir_size(mz_zip_archive *pZip); | ||||
| MINIZ_EXPORT size_t mz_zip_get_central_dir_size(mz_zip_archive *pZip); | ||||
|  | ||||
| /* Extracts a archive file to a memory buffer using no memory allocation. */ | ||||
| /* There must be at least enough room on the stack to store the inflator's state (~34KB or so). */ | ||||
| mz_bool mz_zip_reader_extract_to_mem_no_alloc(mz_zip_archive *pZip, mz_uint file_index, void *pBuf, size_t buf_size, mz_uint flags, void *pUser_read_buf, size_t user_read_buf_size); | ||||
| mz_bool mz_zip_reader_extract_file_to_mem_no_alloc(mz_zip_archive *pZip, const char *pFilename, void *pBuf, size_t buf_size, mz_uint flags, void *pUser_read_buf, size_t user_read_buf_size); | ||||
| MINIZ_EXPORT mz_bool mz_zip_reader_extract_to_mem_no_alloc(mz_zip_archive *pZip, mz_uint file_index, void *pBuf, size_t buf_size, mz_uint flags, void *pUser_read_buf, size_t user_read_buf_size); | ||||
| MINIZ_EXPORT mz_bool mz_zip_reader_extract_file_to_mem_no_alloc(mz_zip_archive *pZip, const char *pFilename, void *pBuf, size_t buf_size, mz_uint flags, void *pUser_read_buf, size_t user_read_buf_size); | ||||
|  | ||||
| /* Extracts a archive file to a memory buffer. */ | ||||
| mz_bool mz_zip_reader_extract_to_mem(mz_zip_archive *pZip, mz_uint file_index, void *pBuf, size_t buf_size, mz_uint flags); | ||||
| mz_bool mz_zip_reader_extract_file_to_mem(mz_zip_archive *pZip, const char *pFilename, void *pBuf, size_t buf_size, mz_uint flags); | ||||
| MINIZ_EXPORT mz_bool mz_zip_reader_extract_to_mem(mz_zip_archive *pZip, mz_uint file_index, void *pBuf, size_t buf_size, mz_uint flags); | ||||
| MINIZ_EXPORT mz_bool mz_zip_reader_extract_file_to_mem(mz_zip_archive *pZip, const char *pFilename, void *pBuf, size_t buf_size, mz_uint flags); | ||||
|  | ||||
| /* Extracts a archive file to a dynamically allocated heap buffer. */ | ||||
| /* The memory will be allocated via the mz_zip_archive's alloc/realloc functions. */ | ||||
| /* Returns NULL and sets the last error on failure. */ | ||||
| void *mz_zip_reader_extract_to_heap(mz_zip_archive *pZip, mz_uint file_index, size_t *pSize, mz_uint flags); | ||||
| void *mz_zip_reader_extract_file_to_heap(mz_zip_archive *pZip, const char *pFilename, size_t *pSize, mz_uint flags); | ||||
| MINIZ_EXPORT void *mz_zip_reader_extract_to_heap(mz_zip_archive *pZip, mz_uint file_index, size_t *pSize, mz_uint flags); | ||||
| MINIZ_EXPORT void *mz_zip_reader_extract_file_to_heap(mz_zip_archive *pZip, const char *pFilename, size_t *pSize, mz_uint flags); | ||||
|  | ||||
| /* Extracts a archive file using a callback function to output the file's data. */ | ||||
| mz_bool mz_zip_reader_extract_to_callback(mz_zip_archive *pZip, mz_uint file_index, mz_file_write_func pCallback, void *pOpaque, mz_uint flags); | ||||
| mz_bool mz_zip_reader_extract_file_to_callback(mz_zip_archive *pZip, const char *pFilename, mz_file_write_func pCallback, void *pOpaque, mz_uint flags); | ||||
| MINIZ_EXPORT mz_bool mz_zip_reader_extract_to_callback(mz_zip_archive *pZip, mz_uint file_index, mz_file_write_func pCallback, void *pOpaque, mz_uint flags); | ||||
| MINIZ_EXPORT mz_bool mz_zip_reader_extract_file_to_callback(mz_zip_archive *pZip, const char *pFilename, mz_file_write_func pCallback, void *pOpaque, mz_uint flags); | ||||
|  | ||||
| /* Extract a file iteratively */ | ||||
| mz_zip_reader_extract_iter_state* mz_zip_reader_extract_iter_new(mz_zip_archive *pZip, mz_uint file_index, mz_uint flags); | ||||
| mz_zip_reader_extract_iter_state* mz_zip_reader_extract_file_iter_new(mz_zip_archive *pZip, const char *pFilename, mz_uint flags); | ||||
| size_t mz_zip_reader_extract_iter_read(mz_zip_reader_extract_iter_state* pState, void* pvBuf, size_t buf_size); | ||||
| mz_bool mz_zip_reader_extract_iter_free(mz_zip_reader_extract_iter_state* pState); | ||||
| MINIZ_EXPORT mz_zip_reader_extract_iter_state* mz_zip_reader_extract_iter_new(mz_zip_archive *pZip, mz_uint file_index, mz_uint flags); | ||||
| MINIZ_EXPORT mz_zip_reader_extract_iter_state* mz_zip_reader_extract_file_iter_new(mz_zip_archive *pZip, const char *pFilename, mz_uint flags); | ||||
| MINIZ_EXPORT size_t mz_zip_reader_extract_iter_read(mz_zip_reader_extract_iter_state* pState, void* pvBuf, size_t buf_size); | ||||
| MINIZ_EXPORT mz_bool mz_zip_reader_extract_iter_free(mz_zip_reader_extract_iter_state* pState); | ||||
|  | ||||
| #ifndef MINIZ_NO_STDIO | ||||
| /* Extracts a archive file to a disk file and sets its last accessed and modified times. */ | ||||
| /* This function only extracts files, not archive directory records. */ | ||||
| mz_bool mz_zip_reader_extract_to_file(mz_zip_archive *pZip, mz_uint file_index, const char *pDst_filename, mz_uint flags); | ||||
| mz_bool mz_zip_reader_extract_file_to_file(mz_zip_archive *pZip, const char *pArchive_filename, const char *pDst_filename, mz_uint flags); | ||||
| MINIZ_EXPORT mz_bool mz_zip_reader_extract_to_file(mz_zip_archive *pZip, mz_uint file_index, const char *pDst_filename, mz_uint flags); | ||||
| MINIZ_EXPORT mz_bool mz_zip_reader_extract_file_to_file(mz_zip_archive *pZip, const char *pArchive_filename, const char *pDst_filename, mz_uint flags); | ||||
|  | ||||
| /* Extracts a archive file starting at the current position in the destination FILE stream. */ | ||||
| mz_bool mz_zip_reader_extract_to_cfile(mz_zip_archive *pZip, mz_uint file_index, MZ_FILE *File, mz_uint flags); | ||||
| mz_bool mz_zip_reader_extract_file_to_cfile(mz_zip_archive *pZip, const char *pArchive_filename, MZ_FILE *pFile, mz_uint flags); | ||||
| MINIZ_EXPORT mz_bool mz_zip_reader_extract_to_cfile(mz_zip_archive *pZip, mz_uint file_index, MZ_FILE *File, mz_uint flags); | ||||
| MINIZ_EXPORT mz_bool mz_zip_reader_extract_file_to_cfile(mz_zip_archive *pZip, const char *pArchive_filename, MZ_FILE *pFile, mz_uint flags); | ||||
| #endif | ||||
|  | ||||
| #if 0 | ||||
| @@ -331,17 +327,17 @@ mz_bool mz_zip_reader_extract_file_to_cfile(mz_zip_archive *pZip, const char *pA | ||||
|  | ||||
| /* This function compares the archive's local headers, the optional local zip64 extended information block, and the optional descriptor following the compressed data vs. the data in the central directory. */ | ||||
| /* It also validates that each file can be successfully uncompressed unless the MZ_ZIP_FLAG_VALIDATE_HEADERS_ONLY is specified. */ | ||||
| mz_bool mz_zip_validate_file(mz_zip_archive *pZip, mz_uint file_index, mz_uint flags); | ||||
| MINIZ_EXPORT mz_bool mz_zip_validate_file(mz_zip_archive *pZip, mz_uint file_index, mz_uint flags); | ||||
|  | ||||
| /* Validates an entire archive by calling mz_zip_validate_file() on each file. */ | ||||
| mz_bool mz_zip_validate_archive(mz_zip_archive *pZip, mz_uint flags); | ||||
| MINIZ_EXPORT mz_bool mz_zip_validate_archive(mz_zip_archive *pZip, mz_uint flags); | ||||
|  | ||||
| /* Misc utils/helpers, valid for ZIP reading or writing */ | ||||
| mz_bool mz_zip_validate_mem_archive(const void *pMem, size_t size, mz_uint flags, mz_zip_error *pErr); | ||||
| mz_bool mz_zip_validate_file_archive(const char *pFilename, mz_uint flags, mz_zip_error *pErr); | ||||
| MINIZ_EXPORT mz_bool mz_zip_validate_mem_archive(const void *pMem, size_t size, mz_uint flags, mz_zip_error *pErr); | ||||
| MINIZ_EXPORT mz_bool mz_zip_validate_file_archive(const char *pFilename, mz_uint flags, mz_zip_error *pErr); | ||||
|  | ||||
| /* Universal end function - calls either mz_zip_reader_end() or mz_zip_writer_end(). */ | ||||
| mz_bool mz_zip_end(mz_zip_archive *pZip); | ||||
| MINIZ_EXPORT mz_bool mz_zip_end(mz_zip_archive *pZip); | ||||
|  | ||||
| /* -------- ZIP writing */ | ||||
|  | ||||
| @@ -350,16 +346,16 @@ mz_bool mz_zip_end(mz_zip_archive *pZip); | ||||
| /* Inits a ZIP archive writer. */ | ||||
| /*Set pZip->m_pWrite (and pZip->m_pIO_opaque) before calling mz_zip_writer_init or mz_zip_writer_init_v2*/ | ||||
| /*The output is streamable, i.e. file_ofs in mz_file_write_func always increases only by n*/ | ||||
| mz_bool mz_zip_writer_init(mz_zip_archive *pZip, mz_uint64 existing_size); | ||||
| mz_bool mz_zip_writer_init_v2(mz_zip_archive *pZip, mz_uint64 existing_size, mz_uint flags); | ||||
| MINIZ_EXPORT mz_bool mz_zip_writer_init(mz_zip_archive *pZip, mz_uint64 existing_size); | ||||
| MINIZ_EXPORT mz_bool mz_zip_writer_init_v2(mz_zip_archive *pZip, mz_uint64 existing_size, mz_uint flags); | ||||
|  | ||||
| mz_bool mz_zip_writer_init_heap(mz_zip_archive *pZip, size_t size_to_reserve_at_beginning, size_t initial_allocation_size); | ||||
| mz_bool mz_zip_writer_init_heap_v2(mz_zip_archive *pZip, size_t size_to_reserve_at_beginning, size_t initial_allocation_size, mz_uint flags); | ||||
| MINIZ_EXPORT mz_bool mz_zip_writer_init_heap(mz_zip_archive *pZip, size_t size_to_reserve_at_beginning, size_t initial_allocation_size); | ||||
| MINIZ_EXPORT mz_bool mz_zip_writer_init_heap_v2(mz_zip_archive *pZip, size_t size_to_reserve_at_beginning, size_t initial_allocation_size, mz_uint flags); | ||||
|  | ||||
| #ifndef MINIZ_NO_STDIO | ||||
| mz_bool mz_zip_writer_init_file(mz_zip_archive *pZip, const char *pFilename, mz_uint64 size_to_reserve_at_beginning); | ||||
| mz_bool mz_zip_writer_init_file_v2(mz_zip_archive *pZip, const char *pFilename, mz_uint64 size_to_reserve_at_beginning, mz_uint flags); | ||||
| mz_bool mz_zip_writer_init_cfile(mz_zip_archive *pZip, MZ_FILE *pFile, mz_uint flags); | ||||
| MINIZ_EXPORT mz_bool mz_zip_writer_init_file(mz_zip_archive *pZip, const char *pFilename, mz_uint64 size_to_reserve_at_beginning); | ||||
| MINIZ_EXPORT mz_bool mz_zip_writer_init_file_v2(mz_zip_archive *pZip, const char *pFilename, mz_uint64 size_to_reserve_at_beginning, mz_uint flags); | ||||
| MINIZ_EXPORT mz_bool mz_zip_writer_init_cfile(mz_zip_archive *pZip, MZ_FILE *pFile, mz_uint flags); | ||||
| #endif | ||||
|  | ||||
| /* Converts a ZIP archive reader object into a writer object, to allow efficient in-place file appends to occur on an existing archive. */ | ||||
| @@ -368,50 +364,57 @@ mz_bool mz_zip_writer_init_cfile(mz_zip_archive *pZip, MZ_FILE *pFile, mz_uint f | ||||
| /* Finally, for archives opened using mz_zip_reader_init, the mz_zip_archive's user provided m_pWrite function cannot be NULL. */ | ||||
| /* Note: In-place archive modification is not recommended unless you know what you're doing, because if execution stops or something goes wrong before */ | ||||
| /* the archive is finalized the file's central directory will be hosed. */ | ||||
| mz_bool mz_zip_writer_init_from_reader(mz_zip_archive *pZip, const char *pFilename); | ||||
| mz_bool mz_zip_writer_init_from_reader_v2(mz_zip_archive *pZip, const char *pFilename, mz_uint flags); | ||||
| MINIZ_EXPORT mz_bool mz_zip_writer_init_from_reader(mz_zip_archive *pZip, const char *pFilename); | ||||
| MINIZ_EXPORT mz_bool mz_zip_writer_init_from_reader_v2(mz_zip_archive *pZip, const char *pFilename, mz_uint flags); | ||||
|  | ||||
| /* Adds the contents of a memory buffer to an archive. These functions record the current local time into the archive. */ | ||||
| /* To add a directory entry, call this method with an archive name ending in a forwardslash with an empty buffer. */ | ||||
| /* level_and_flags - compression level (0-10, see MZ_BEST_SPEED, MZ_BEST_COMPRESSION, etc.) logically OR'd with zero or more mz_zip_flags, or just set to MZ_DEFAULT_COMPRESSION. */ | ||||
| mz_bool mz_zip_writer_add_mem(mz_zip_archive *pZip, const char *pArchive_name, const void *pBuf, size_t buf_size, mz_uint level_and_flags); | ||||
| MINIZ_EXPORT mz_bool mz_zip_writer_add_mem(mz_zip_archive *pZip, const char *pArchive_name, const void *pBuf, size_t buf_size, mz_uint level_and_flags); | ||||
|  | ||||
| /* Like mz_zip_writer_add_mem(), except you can specify a file comment field, and optionally supply the function with already compressed data. */ | ||||
| /* uncomp_size/uncomp_crc32 are only used if the MZ_ZIP_FLAG_COMPRESSED_DATA flag is specified. */ | ||||
| mz_bool mz_zip_writer_add_mem_ex(mz_zip_archive *pZip, const char *pArchive_name, const void *pBuf, size_t buf_size, const void *pComment, mz_uint16 comment_size, mz_uint level_and_flags, | ||||
|                                  mz_uint64 uncomp_size, mz_uint32 uncomp_crc32); | ||||
| MINIZ_EXPORT mz_bool mz_zip_writer_add_mem_ex(mz_zip_archive *pZip, const char *pArchive_name, const void *pBuf, size_t buf_size, const void *pComment, mz_uint16 comment_size, mz_uint level_and_flags, | ||||
|                                               mz_uint64 uncomp_size, mz_uint32 uncomp_crc32); | ||||
|  | ||||
| MINIZ_EXPORT mz_bool mz_zip_writer_add_mem_ex_v2(mz_zip_archive *pZip, const char *pArchive_name, const void *pBuf, size_t buf_size, const void *pComment, mz_uint16 comment_size, mz_uint level_and_flags, | ||||
|                                                  mz_uint64 uncomp_size, mz_uint32 uncomp_crc32, MZ_TIME_T *last_modified, const char *user_extra_data_local, mz_uint user_extra_data_local_len, | ||||
|                                                  const char *user_extra_data_central, mz_uint user_extra_data_central_len); | ||||
|  | ||||
| /* Adds the contents of a file to an archive. This function also records the disk file's modified time into the archive. */ | ||||
| /* File data is supplied via a read callback function. User mz_zip_writer_add_(c)file to add a file directly.*/ | ||||
| MINIZ_EXPORT mz_bool mz_zip_writer_add_read_buf_callback(mz_zip_archive *pZip, const char *pArchive_name, mz_file_read_func read_callback, void* callback_opaque, mz_uint64 max_size, | ||||
| 	const MZ_TIME_T *pFile_time, const void *pComment, mz_uint16 comment_size, mz_uint level_and_flags, const char *user_extra_data_local, mz_uint user_extra_data_local_len, | ||||
| 	const char *user_extra_data_central, mz_uint user_extra_data_central_len); | ||||
|  | ||||
| mz_bool mz_zip_writer_add_mem_ex_v2(mz_zip_archive *pZip, const char *pArchive_name, const void *pBuf, size_t buf_size, const void *pComment, mz_uint16 comment_size, mz_uint level_and_flags, | ||||
|                                     mz_uint64 uncomp_size, mz_uint32 uncomp_crc32, MZ_TIME_T *last_modified, const char *user_extra_data_local, mz_uint user_extra_data_local_len, | ||||
|                                     const char *user_extra_data_central, mz_uint user_extra_data_central_len); | ||||
|  | ||||
| #ifndef MINIZ_NO_STDIO | ||||
| /* Adds the contents of a disk file to an archive. This function also records the disk file's modified time into the archive. */ | ||||
| /* level_and_flags - compression level (0-10, see MZ_BEST_SPEED, MZ_BEST_COMPRESSION, etc.) logically OR'd with zero or more mz_zip_flags, or just set to MZ_DEFAULT_COMPRESSION. */ | ||||
| mz_bool mz_zip_writer_add_file(mz_zip_archive *pZip, const char *pArchive_name, const char *pSrc_filename, const void *pComment, mz_uint16 comment_size, mz_uint level_and_flags); | ||||
| MINIZ_EXPORT mz_bool mz_zip_writer_add_file(mz_zip_archive *pZip, const char *pArchive_name, const char *pSrc_filename, const void *pComment, mz_uint16 comment_size, mz_uint level_and_flags); | ||||
|  | ||||
| /* Like mz_zip_writer_add_file(), except the file data is read from the specified FILE stream. */ | ||||
| mz_bool mz_zip_writer_add_cfile(mz_zip_archive *pZip, const char *pArchive_name, MZ_FILE *pSrc_file, mz_uint64 size_to_add, | ||||
| MINIZ_EXPORT mz_bool mz_zip_writer_add_cfile(mz_zip_archive *pZip, const char *pArchive_name, MZ_FILE *pSrc_file, mz_uint64 max_size, | ||||
|                                 const MZ_TIME_T *pFile_time, const void *pComment, mz_uint16 comment_size, mz_uint level_and_flags, const char *user_extra_data_local, mz_uint user_extra_data_local_len, | ||||
|                                 const char *user_extra_data_central, mz_uint user_extra_data_central_len); | ||||
| #endif | ||||
|  | ||||
| /* Adds a file to an archive by fully cloning the data from another archive. */ | ||||
| /* This function fully clones the source file's compressed data (no recompression), along with its full filename, extra data (it may add or modify the zip64 local header extra data field), and the optional descriptor following the compressed data. */ | ||||
| mz_bool mz_zip_writer_add_from_zip_reader(mz_zip_archive *pZip, mz_zip_archive *pSource_zip, mz_uint src_file_index); | ||||
| MINIZ_EXPORT mz_bool mz_zip_writer_add_from_zip_reader(mz_zip_archive *pZip, mz_zip_archive *pSource_zip, mz_uint src_file_index); | ||||
|  | ||||
| /* Finalizes the archive by writing the central directory records followed by the end of central directory record. */ | ||||
| /* After an archive is finalized, the only valid call on the mz_zip_archive struct is mz_zip_writer_end(). */ | ||||
| /* An archive must be manually finalized by calling this function for it to be valid. */ | ||||
| mz_bool mz_zip_writer_finalize_archive(mz_zip_archive *pZip); | ||||
| MINIZ_EXPORT mz_bool mz_zip_writer_finalize_archive(mz_zip_archive *pZip); | ||||
|  | ||||
| /* Finalizes a heap archive, returning a poiner to the heap block and its size. */ | ||||
| /* The heap block will be allocated using the mz_zip_archive's alloc/realloc callbacks. */ | ||||
| mz_bool mz_zip_writer_finalize_heap_archive(mz_zip_archive *pZip, void **ppBuf, size_t *pSize); | ||||
| MINIZ_EXPORT mz_bool mz_zip_writer_finalize_heap_archive(mz_zip_archive *pZip, void **ppBuf, size_t *pSize); | ||||
|  | ||||
| /* Ends archive writing, freeing all allocations, and closing the output file if mz_zip_writer_init_file() was used. */ | ||||
| /* Note for the archive to be valid, it *must* have been finalized before ending (this function will not do it for you). */ | ||||
| mz_bool mz_zip_writer_end(mz_zip_archive *pZip); | ||||
| MINIZ_EXPORT mz_bool mz_zip_writer_end(mz_zip_archive *pZip); | ||||
|  | ||||
| /* -------- Misc. high-level helper functions: */ | ||||
|  | ||||
| @@ -419,14 +422,14 @@ mz_bool mz_zip_writer_end(mz_zip_archive *pZip); | ||||
| /* Note this is NOT a fully safe operation. If it crashes or dies in some way your archive can be left in a screwed up state (without a central directory). */ | ||||
| /* level_and_flags - compression level (0-10, see MZ_BEST_SPEED, MZ_BEST_COMPRESSION, etc.) logically OR'd with zero or more mz_zip_flags, or just set to MZ_DEFAULT_COMPRESSION. */ | ||||
| /* TODO: Perhaps add an option to leave the existing central dir in place in case the add dies? We could then truncate the file (so the old central dir would be at the end) if something goes wrong. */ | ||||
| mz_bool mz_zip_add_mem_to_archive_file_in_place(const char *pZip_filename, const char *pArchive_name, const void *pBuf, size_t buf_size, const void *pComment, mz_uint16 comment_size, mz_uint level_and_flags); | ||||
| mz_bool mz_zip_add_mem_to_archive_file_in_place_v2(const char *pZip_filename, const char *pArchive_name, const void *pBuf, size_t buf_size, const void *pComment, mz_uint16 comment_size, mz_uint level_and_flags, mz_zip_error *pErr); | ||||
| MINIZ_EXPORT mz_bool mz_zip_add_mem_to_archive_file_in_place(const char *pZip_filename, const char *pArchive_name, const void *pBuf, size_t buf_size, const void *pComment, mz_uint16 comment_size, mz_uint level_and_flags); | ||||
| MINIZ_EXPORT mz_bool mz_zip_add_mem_to_archive_file_in_place_v2(const char *pZip_filename, const char *pArchive_name, const void *pBuf, size_t buf_size, const void *pComment, mz_uint16 comment_size, mz_uint level_and_flags, mz_zip_error *pErr); | ||||
|  | ||||
| /* Reads a single file from an archive into a heap block. */ | ||||
| /* If pComment is not NULL, only the file with the specified comment will be extracted. */ | ||||
| /* Returns NULL on failure. */ | ||||
| void *mz_zip_extract_archive_file_to_heap(const char *pZip_filename, const char *pArchive_name, size_t *pSize, mz_uint flags); | ||||
| void *mz_zip_extract_archive_file_to_heap_v2(const char *pZip_filename, const char *pArchive_name, const char *pComment, size_t *pSize, mz_uint flags, mz_zip_error *pErr); | ||||
| MINIZ_EXPORT void *mz_zip_extract_archive_file_to_heap(const char *pZip_filename, const char *pArchive_name, size_t *pSize, mz_uint flags); | ||||
| MINIZ_EXPORT void *mz_zip_extract_archive_file_to_heap_v2(const char *pZip_filename, const char *pArchive_name, const char *pComment, size_t *pSize, mz_uint flags, mz_zip_error *pErr); | ||||
|  | ||||
| #endif /* #ifndef MINIZ_NO_ARCHIVE_WRITING_APIS */ | ||||
|  | ||||
|   | ||||
| @@ -31,7 +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. | ||||
|  | ||||
|  | ||||
| [](https://travis-ci.org/uroni/miniz) | ||||
| 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. | ||||
|   | ||||
							
								
								
									
										25
									
								
								tests/checksum_fuzzer.c
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										25
									
								
								tests/checksum_fuzzer.c
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,25 @@ | ||||
| /* Derived from zlib fuzzers at http://github.com/google/oss-fuzz/tree/master/projects/zlib, | ||||
|  * see ossfuzz.sh for full license text. | ||||
| */ | ||||
|  | ||||
| #include <stddef.h> | ||||
| #include <stdint.h> | ||||
| #include <inttypes.h> | ||||
|  | ||||
| #include "miniz.h" | ||||
|  | ||||
| static const size_t kMaxSize = 1024 * 1024; | ||||
|  | ||||
| int LLVMFuzzerTestOneInput(const uint8_t *data, size_t dataLen) | ||||
| { | ||||
|     /* Discard inputs larger than 1Mb. */ | ||||
|     if (dataLen < 1 || dataLen > kMaxSize) return 0; | ||||
|  | ||||
|     uint32_t crc = crc32(0L, NULL, 0); | ||||
|     uint32_t adler = adler32(0L, NULL, 0); | ||||
|  | ||||
|     crc = crc32(crc, data, (uint32_t) dataLen); | ||||
|     adler = adler32(adler, data, (uint32_t) dataLen); | ||||
|  | ||||
|     return 0; | ||||
| } | ||||
							
								
								
									
										88
									
								
								tests/compress_fuzzer.c
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										88
									
								
								tests/compress_fuzzer.c
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,88 @@ | ||||
| /* Derived from zlib fuzzers at http://github.com/google/oss-fuzz/tree/master/projects/zlib, | ||||
|  * see ossfuzz.sh for full license text. | ||||
| */ | ||||
|  | ||||
| #include <stdio.h> | ||||
| #include <stddef.h> | ||||
| #include <stdint.h> | ||||
| #include <string.h> | ||||
| #include <assert.h> | ||||
| #include <stdlib.h> | ||||
| #include <inttypes.h> | ||||
| #include "miniz.h" | ||||
|  | ||||
| static const uint8_t *data; | ||||
| static size_t dataLen; | ||||
|  | ||||
| static void check_compress_level(uint8_t *compr, size_t comprLen, | ||||
|                                  uint8_t *uncompr, size_t uncomprLen, | ||||
|                                  int level) | ||||
| { | ||||
|     compress2(compr, &comprLen, data, dataLen, level); | ||||
|     uncompress(uncompr, &uncomprLen, compr, comprLen); | ||||
|  | ||||
|     /* Make sure compress + uncompress gives back the input data. */ | ||||
|     assert(dataLen == uncomprLen); | ||||
|     assert(0 == memcmp(data, uncompr, dataLen)); | ||||
| } | ||||
|  | ||||
| #define put_byte(s, i, c) {s[i] = (unsigned char)(c);} | ||||
|  | ||||
| static void write_zlib_header(uint8_t *s) | ||||
| { | ||||
|     unsigned level_flags = 0; /* compression level (0..3) */ | ||||
|     unsigned w_bits = 8; /* window size log2(w_size)  (8..16) */ | ||||
|     unsigned int header = (Z_DEFLATED + ((w_bits-8)<<4)) << 8; | ||||
|     header |= (level_flags << 6); | ||||
|  | ||||
|     header += 31 - (header % 31); | ||||
|  | ||||
|     /* s is guaranteed to be longer than 2 bytes. */ | ||||
|     put_byte(s, 0, (unsigned char)(header >> 8)); | ||||
|     put_byte(s, 1, (unsigned char)(header & 0xff)); | ||||
| } | ||||
|  | ||||
| static void check_decompress(uint8_t *compr, size_t comprLen) | ||||
| { | ||||
|     /* We need to write a valid zlib header of size two bytes. Copy the input data | ||||
|         in a larger buffer. Do not modify the input data to avoid libFuzzer error: | ||||
|         fuzz target overwrites its const input. */ | ||||
|     size_t copyLen = dataLen + 2; | ||||
|     uint8_t *copy = malloc(copyLen); | ||||
|     memcpy(copy + 2, data, dataLen); | ||||
|     write_zlib_header(copy); | ||||
|  | ||||
|     uncompress(compr, &comprLen, copy, copyLen); | ||||
|     free(copy); | ||||
| } | ||||
|  | ||||
| int LLVMFuzzerTestOneInput(const uint8_t *d, size_t size) | ||||
| { | ||||
|     /* compressBound does not provide enough space for low compression levels. */ | ||||
|     size_t comprLen = 100 + 2 * compressBound(size); | ||||
|     size_t uncomprLen = size; | ||||
|     uint8_t *compr, *uncompr; | ||||
|  | ||||
|     /* Discard inputs larger than 1Mb. */ | ||||
|     static size_t kMaxSize = 1024 * 1024; | ||||
|  | ||||
|     if (size < 1 || size > kMaxSize) | ||||
|     return 0; | ||||
|  | ||||
|     data = d; | ||||
|     dataLen = size; | ||||
|     compr = calloc(1, comprLen); | ||||
|     uncompr = calloc(1, uncomprLen); | ||||
|  | ||||
|     check_compress_level(compr, comprLen, uncompr, uncomprLen, 1); | ||||
|     check_compress_level(compr, comprLen, uncompr, uncomprLen, 3); | ||||
|     check_compress_level(compr, comprLen, uncompr, uncomprLen, 6); | ||||
|     check_compress_level(compr, comprLen, uncompr, uncomprLen, 7); | ||||
|  | ||||
|     check_decompress(compr, comprLen); | ||||
|  | ||||
|     free(compr); | ||||
|     free(uncompr); | ||||
|  | ||||
|     return 0; | ||||
| } | ||||
							
								
								
									
										87
									
								
								tests/flush_fuzzer.c
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										87
									
								
								tests/flush_fuzzer.c
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,87 @@ | ||||
| /* Derived from zlib fuzzers at http://github.com/google/oss-fuzz/tree/master/projects/zlib, | ||||
|  * see ossfuzz.sh for full license text. | ||||
| */ | ||||
|  | ||||
| #include <stdio.h> | ||||
| #include <stddef.h> | ||||
| #include <stdint.h> | ||||
| #include <string.h> | ||||
| #include <stdlib.h> | ||||
| #include <inttypes.h> | ||||
|  | ||||
| #include "miniz.h" | ||||
|  | ||||
| #define CHECK_ERR(err, msg) { \ | ||||
|     if (err != Z_OK) { \ | ||||
|         fprintf(stderr, "%s error: %d\n", msg, err); \ | ||||
|         exit(1); \ | ||||
|     } \ | ||||
| } | ||||
|  | ||||
| static const uint8_t *data; | ||||
| static size_t dataLen; | ||||
| static alloc_func zalloc = NULL; | ||||
| static free_func zfree = NULL; | ||||
|  | ||||
|  | ||||
| void test_flush(unsigned char *compr, size_t *comprLen) | ||||
| { | ||||
|     z_stream c_stream; /* compression stream */ | ||||
|     int err; | ||||
|     unsigned int len = dataLen; | ||||
|  | ||||
|     c_stream.zalloc = zalloc; | ||||
|     c_stream.zfree = zfree; | ||||
|     c_stream.opaque = NULL; | ||||
|  | ||||
|     err = deflateInit(&c_stream, Z_DEFAULT_COMPRESSION); | ||||
|     CHECK_ERR(err, "deflateInit"); | ||||
|  | ||||
|     c_stream.next_in = (Bytef *)data; | ||||
|     c_stream.next_out = compr; | ||||
|     c_stream.avail_in = 3; | ||||
|     c_stream.avail_out = (unsigned int)*comprLen; | ||||
|     err = deflate(&c_stream, Z_FULL_FLUSH); | ||||
|     CHECK_ERR(err, "deflate flush 1"); | ||||
|  | ||||
|     compr[3]++; /* force an error in first compressed block */ | ||||
|     c_stream.avail_in = len - 3; | ||||
|  | ||||
|     err = deflate(&c_stream, Z_FINISH); | ||||
|  | ||||
|     if (err != Z_STREAM_END) | ||||
|     { | ||||
|         CHECK_ERR(err, "deflate flush 2"); | ||||
|     } | ||||
|  | ||||
|     err = deflateEnd(&c_stream); | ||||
|     CHECK_ERR(err, "deflateEnd"); | ||||
|  | ||||
|     *comprLen = (size_t)c_stream.total_out; | ||||
| } | ||||
|  | ||||
| int LLVMFuzzerTestOneInput(const uint8_t *d, size_t size) | ||||
| { | ||||
|     size_t comprLen = 100 + 2 * compressBound(size); | ||||
|     size_t uncomprLen = size; | ||||
|     uint8_t *compr, *uncompr; | ||||
|  | ||||
|     /* Discard inputs larger than 1Mb. */ | ||||
|     static const size_t kMaxSize = 1024 * 1024; | ||||
|  | ||||
|     /* This test requires at least 3 bytes of input data. */ | ||||
|     if (size <= 3 || size > kMaxSize) | ||||
|     return 0; | ||||
|  | ||||
|     data = d; | ||||
|     dataLen = size; | ||||
|     compr = calloc(1, comprLen); | ||||
|     uncompr = calloc(1, uncomprLen); | ||||
|  | ||||
|     test_flush(compr, &comprLen); | ||||
|  | ||||
|     free(compr); | ||||
|     free(uncompr); | ||||
|  | ||||
|     return 0; | ||||
| } | ||||
							
								
								
									
										54
									
								
								tests/fuzz_main.c
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										54
									
								
								tests/fuzz_main.c
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,54 @@ | ||||
| #include <stdio.h> | ||||
| #include <stdint.h> | ||||
| #include <stdlib.h> | ||||
|  | ||||
| /* Fuzz target entry point for building without libFuzzer */ | ||||
|  | ||||
| int LLVMFuzzerTestOneInput(const uint8_t *d, size_t size); | ||||
|  | ||||
| int main(int argc, char **argv) | ||||
| { | ||||
|     FILE *f; | ||||
|     char *buf = NULL; | ||||
|     long siz_buf; | ||||
|  | ||||
|     if(argc < 2) | ||||
|     { | ||||
|         fprintf(stderr, "no input file\n"); | ||||
|         goto err; | ||||
|     } | ||||
|  | ||||
|     f = fopen(argv[1], "rb"); | ||||
|     if(f == NULL) | ||||
|     { | ||||
|         fprintf(stderr, "error opening input file %s\n", argv[1]); | ||||
|         goto err; | ||||
|     } | ||||
|  | ||||
|     fseek(f, 0, SEEK_END); | ||||
|  | ||||
|     siz_buf = ftell(f); | ||||
|     rewind(f); | ||||
|  | ||||
|     if(siz_buf < 1) goto err; | ||||
|  | ||||
|     buf = (char*)malloc(siz_buf); | ||||
|     if(buf == NULL) | ||||
|     { | ||||
|         fprintf(stderr, "malloc() failed\n"); | ||||
|         goto err; | ||||
|     } | ||||
|  | ||||
|     if(fread(buf, siz_buf, 1, f) != 1) | ||||
|     { | ||||
|         fprintf(stderr, "fread() failed\n"); | ||||
|         goto err; | ||||
|     } | ||||
|  | ||||
|     (void)LLVMFuzzerTestOneInput((uint8_t*)buf, siz_buf); | ||||
|  | ||||
| err: | ||||
|     free(buf); | ||||
|  | ||||
|     return 0; | ||||
| } | ||||
							
								
								
									
										130
									
								
								tests/large_fuzzer.c
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										130
									
								
								tests/large_fuzzer.c
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,130 @@ | ||||
| /* Derived from zlib fuzzers at http://github.com/google/oss-fuzz/tree/master/projects/zlib, | ||||
|  * see ossfuzz.sh for full license text. | ||||
| */ | ||||
|  | ||||
| #include <stdio.h> | ||||
| #include <stddef.h> | ||||
| #include <stdint.h> | ||||
| #include <string.h> | ||||
| #include <stdlib.h> | ||||
| #include <inttypes.h> | ||||
|  | ||||
| #include "miniz.h" | ||||
|  | ||||
| #define CHECK_ERR(err, msg) { \ | ||||
|     if (err != Z_OK) { \ | ||||
|         fprintf(stderr, "%s error: %d\n", msg, err); \ | ||||
|         exit(1); \ | ||||
|     } \ | ||||
| } | ||||
|  | ||||
| static const uint8_t *data; | ||||
| static size_t dataLen; | ||||
| static alloc_func zalloc = NULL; | ||||
| static free_func zfree = NULL; | ||||
| static unsigned int diff; | ||||
|  | ||||
| /* Test deflate() with large buffers and dynamic change of compression level */ | ||||
| void test_large_deflate(unsigned char *compr, size_t comprLen, | ||||
|                         unsigned char *uncompr, size_t uncomprLen) | ||||
| { | ||||
|     z_stream c_stream; /* compression stream */ | ||||
|     int err; | ||||
|  | ||||
|     c_stream.zalloc = zalloc; | ||||
|     c_stream.zfree = zfree; | ||||
|     c_stream.opaque = NULL; | ||||
|  | ||||
|     err = deflateInit(&c_stream, Z_BEST_COMPRESSION); | ||||
|     CHECK_ERR(err, "deflateInit"); | ||||
|  | ||||
|     c_stream.next_out = compr; | ||||
|     c_stream.avail_out = (unsigned int)comprLen; | ||||
|  | ||||
|     /* At this point, uncompr is still mostly zeroes, so it should compress | ||||
|     * very well: | ||||
|     */ | ||||
|     c_stream.next_in = uncompr; | ||||
|     c_stream.avail_in = (unsigned int)uncomprLen; | ||||
|     err = deflate(&c_stream, Z_NO_FLUSH); | ||||
|     CHECK_ERR(err, "deflate large 1"); | ||||
|  | ||||
|     if (c_stream.avail_in != 0) | ||||
|     { | ||||
|         fprintf(stderr, "deflate not greedy\n"); | ||||
|         exit(1); | ||||
|     } | ||||
|  | ||||
|     /* Feed in already compressed data: */ | ||||
|     c_stream.next_in = compr; | ||||
|     diff = (unsigned int)(c_stream.next_out - compr); | ||||
|     c_stream.avail_in = diff; | ||||
|  | ||||
|     deflate(&c_stream, Z_NO_FLUSH); | ||||
|     err = deflate(&c_stream, Z_FINISH); | ||||
|  | ||||
|     if (err != Z_STREAM_END) | ||||
|     { | ||||
|         fprintf(stderr, "deflate large should report Z_STREAM_END\n"); | ||||
|         exit(1); | ||||
|     } | ||||
|     err = deflateEnd(&c_stream); | ||||
|     CHECK_ERR(err, "deflateEnd"); | ||||
| } | ||||
|  | ||||
| /* Test inflate() with large buffers */ | ||||
| void test_large_inflate(unsigned char *compr, size_t comprLen, | ||||
|                         unsigned char *uncompr, size_t uncomprLen) | ||||
| { | ||||
|     int err; | ||||
|     z_stream d_stream; /* decompression stream */ | ||||
|  | ||||
|     d_stream.zalloc = zalloc; | ||||
|     d_stream.zfree = zfree; | ||||
|     d_stream.opaque = NULL; | ||||
|  | ||||
|     d_stream.next_in = compr; | ||||
|     d_stream.avail_in = (unsigned int)comprLen; | ||||
|  | ||||
|     err = inflateInit(&d_stream); | ||||
|     CHECK_ERR(err, "inflateInit"); | ||||
|  | ||||
|     for (;;) | ||||
|     { | ||||
|         d_stream.next_out = uncompr; /* discard the output */ | ||||
|         d_stream.avail_out = (unsigned int)uncomprLen; | ||||
|         err = inflate(&d_stream, Z_NO_FLUSH); | ||||
|         if (err == Z_STREAM_END) break; | ||||
|  | ||||
|         CHECK_ERR(err, "large inflate"); | ||||
|     } | ||||
|  | ||||
|     err = inflateEnd(&d_stream); | ||||
|     CHECK_ERR(err, "inflateEnd"); | ||||
| } | ||||
|  | ||||
| int LLVMFuzzerTestOneInput(const uint8_t *d, size_t size) | ||||
| { | ||||
|     size_t comprLen = 100 + 3 * size; | ||||
|     size_t uncomprLen = comprLen; | ||||
|     uint8_t *compr, *uncompr; | ||||
|  | ||||
|     /* Discard inputs larger than 512Kb. */ | ||||
|     static size_t kMaxSize = 512 * 1024; | ||||
|  | ||||
|     if (size < 1 || size > kMaxSize) | ||||
|     return 0; | ||||
|  | ||||
|     data = d; | ||||
|     dataLen = size; | ||||
|     compr = calloc(1, comprLen); | ||||
|     uncompr = calloc(1, uncomprLen); | ||||
|  | ||||
|     test_large_deflate(compr, comprLen, uncompr, uncomprLen); | ||||
|     test_large_inflate(compr, comprLen, uncompr, uncomprLen); | ||||
|  | ||||
|     free(compr); | ||||
|     free(uncompr); | ||||
|  | ||||
|     return 0; | ||||
| } | ||||
							
								
								
									
										42
									
								
								tests/ossfuzz.sh
									
									
									
									
									
										Executable file
									
								
							
							
						
						
									
										42
									
								
								tests/ossfuzz.sh
									
									
									
									
									
										Executable file
									
								
							| @@ -0,0 +1,42 @@ | ||||
| #!/bin/bash -eu | ||||
| # Copyright 2020 Google Inc. | ||||
| # | ||||
| # Licensed under the Apache License, Version 2.0 (the "License"); | ||||
| # you may not use this file except in compliance with the License. | ||||
| # You may obtain a copy of the License at | ||||
| # | ||||
| #      http://www.apache.org/licenses/LICENSE-2.0 | ||||
| # | ||||
| # Unless required by applicable law or agreed to in writing, software | ||||
| # distributed under the License is distributed on an "AS IS" BASIS, | ||||
| # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||||
| # See the License for the specific language governing permissions and | ||||
| # limitations under the License. | ||||
| # | ||||
| ################################################################################ | ||||
|  | ||||
| # This script is meant to be run by | ||||
| # https://github.com/google/oss-fuzz/blob/master/projects/miniz/Dockerfile | ||||
|  | ||||
| mkdir build | ||||
| cd build | ||||
| cmake .. -DAMALGAMATE_SOURCES=ON -DBUILD_SHARED_LIBS=OFF -DBUILD_FUZZERS=ON | ||||
| make -j$(nproc) | ||||
| cd .. | ||||
|  | ||||
| zip $OUT/seed_corpus.zip *.* | ||||
|  | ||||
| for f in $(find $SRC -name '*_fuzzer.c'); do | ||||
|     b=$(basename -s .c $f) | ||||
|     $CC $CFLAGS -Ibuild/amalgamation $f -c -o /tmp/$b.o | ||||
|     $CXX $CXXFLAGS -stdlib=libc++ -Ibuild/amalgamation /tmp/$b.o -o $OUT/$b $LIB_FUZZING_ENGINE ./build/libminiz.a | ||||
|     rm -f /tmp/$b.o | ||||
|     ln -sf $OUT/seed_corpus.zip $OUT/${b}_seed_corpus.zip | ||||
| done | ||||
|  | ||||
|  | ||||
| # Add .zip input file for the zip fuzzer | ||||
| rm -f $OUT/zip_fuzzer_seed_corpus.zip | ||||
| zip $OUT/zip_fuzzer_seed_corpus.zip $OUT/seed_corpus.zip | ||||
|  | ||||
| cp tests/zip.dict $OUT/zip_fuzzer.dict | ||||
							
								
								
									
										124
									
								
								tests/small_fuzzer.c
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										124
									
								
								tests/small_fuzzer.c
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,124 @@ | ||||
| /* Derived from zlib fuzzers at http://github.com/google/oss-fuzz/tree/master/projects/zlib, | ||||
|  * see ossfuzz.sh for full license text. | ||||
| */ | ||||
|  | ||||
| #include <stdio.h> | ||||
| #include <stddef.h> | ||||
| #include <stdint.h> | ||||
| #include <string.h> | ||||
| #include <stdlib.h> | ||||
| #include <inttypes.h> | ||||
|  | ||||
| #include "miniz.h" | ||||
|  | ||||
| #define CHECK_ERR(err, msg) { \ | ||||
|     if (err != Z_OK) { \ | ||||
|         fprintf(stderr, "%s error: %d\n", msg, err); \ | ||||
|         exit(1); \ | ||||
|     } \ | ||||
| } | ||||
|  | ||||
| static const uint8_t *data; | ||||
| static size_t dataLen; | ||||
| static alloc_func zalloc = NULL; | ||||
| static free_func zfree = NULL; | ||||
|  | ||||
| /* Test deflate() with small buffers */ | ||||
| void test_deflate(unsigned char *compr, size_t comprLen) | ||||
| { | ||||
|     z_stream c_stream; /* compression stream */ | ||||
|     int err; | ||||
|     unsigned long len = dataLen; | ||||
|  | ||||
|     c_stream.zalloc = zalloc; | ||||
|     c_stream.zfree = zfree; | ||||
|     c_stream.opaque = NULL; | ||||
|  | ||||
|     err = deflateInit(&c_stream, Z_DEFAULT_COMPRESSION); | ||||
|     CHECK_ERR(err, "deflateInit"); | ||||
|  | ||||
|     c_stream.next_in = (Bytef *)data; | ||||
|     c_stream.next_out = compr; | ||||
|  | ||||
|     while (c_stream.total_in != len && c_stream.total_out < comprLen) | ||||
|     { | ||||
|         c_stream.avail_in = c_stream.avail_out = 1; /* force small buffers */ | ||||
|         err = deflate(&c_stream, Z_NO_FLUSH); | ||||
|         CHECK_ERR(err, "deflate small 1"); | ||||
|     } | ||||
|  | ||||
|     /* Finish the stream, still forcing small buffers: */ | ||||
|     for (;;) | ||||
|     { | ||||
|         c_stream.avail_out = 1; | ||||
|         err = deflate(&c_stream, Z_FINISH); | ||||
|         if (err == Z_STREAM_END) | ||||
|             break; | ||||
|         CHECK_ERR(err, "deflate small 2"); | ||||
|     } | ||||
|  | ||||
|     err = deflateEnd(&c_stream); | ||||
|     CHECK_ERR(err, "deflateEnd"); | ||||
| } | ||||
|  | ||||
| /* Test inflate() with small buffers */ | ||||
| void test_inflate(unsigned char *compr, size_t comprLen, unsigned char *uncompr, size_t uncomprLen) | ||||
| { | ||||
|     int err; | ||||
|     z_stream d_stream; /* decompression stream */ | ||||
|  | ||||
|     d_stream.zalloc = zalloc; | ||||
|     d_stream.zfree = zfree; | ||||
|     d_stream.opaque = NULL; | ||||
|  | ||||
|     d_stream.next_in = compr; | ||||
|     d_stream.avail_in = 0; | ||||
|     d_stream.next_out = uncompr; | ||||
|  | ||||
|     err = inflateInit(&d_stream); | ||||
|     CHECK_ERR(err, "inflateInit"); | ||||
|  | ||||
|     while (d_stream.total_out < uncomprLen && d_stream.total_in < comprLen) | ||||
|     { | ||||
|         d_stream.avail_in = d_stream.avail_out = 1; /* force small buffers */ | ||||
|         err = inflate(&d_stream, Z_NO_FLUSH); | ||||
|         if (err == Z_STREAM_END) | ||||
|             break; | ||||
|         CHECK_ERR(err, "inflate"); | ||||
|     } | ||||
|  | ||||
|     err = inflateEnd(&d_stream); | ||||
|     CHECK_ERR(err, "inflateEnd"); | ||||
|  | ||||
|     if (memcmp(uncompr, data, dataLen)) | ||||
|     { | ||||
|         fprintf(stderr, "bad inflate\n"); | ||||
|         exit(1); | ||||
|     } | ||||
| } | ||||
|  | ||||
| int LLVMFuzzerTestOneInput(const uint8_t *d, size_t size) | ||||
| { | ||||
|     size_t comprLen = compressBound(size); | ||||
|     size_t uncomprLen = size; | ||||
|     uint8_t *compr, *uncompr; | ||||
|  | ||||
|     /* Discard inputs larger than 1Mb. */ | ||||
|     static size_t kMaxSize = 1024 * 1024; | ||||
|  | ||||
|     if (size < 1 || size > kMaxSize) | ||||
|     return 0; | ||||
|  | ||||
|     data = d; | ||||
|     dataLen = size; | ||||
|     compr = calloc(1, comprLen); | ||||
|     uncompr = calloc(1, uncomprLen); | ||||
|  | ||||
|     test_deflate(compr, comprLen); | ||||
|     test_inflate(compr, comprLen, uncompr, uncomprLen); | ||||
|  | ||||
|     free(compr); | ||||
|     free(uncompr); | ||||
|  | ||||
|     return 0; | ||||
| } | ||||
							
								
								
									
										20
									
								
								tests/uncompress2_fuzzer.c
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										20
									
								
								tests/uncompress2_fuzzer.c
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,20 @@ | ||||
| /* Derived from zlib fuzzers at http://github.com/google/oss-fuzz/tree/master/projects/zlib, | ||||
|  * see ossfuzz.sh for full license text. | ||||
| */ | ||||
|  | ||||
| #include <stddef.h> | ||||
| #include <stdint.h> | ||||
| #include <string.h> | ||||
|  | ||||
| #include "miniz.h" | ||||
|  | ||||
| static unsigned char buffer[256 * 1024] = { 0 }; | ||||
|  | ||||
| int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) | ||||
| { | ||||
|     unsigned long int buffer_length = sizeof(buffer); | ||||
|  | ||||
|     if (Z_OK != uncompress2(buffer, &buffer_length, data, &size)) return 0; | ||||
|      | ||||
|     return 0; | ||||
| } | ||||
							
								
								
									
										30
									
								
								tests/uncompress_fuzzer.c
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										30
									
								
								tests/uncompress_fuzzer.c
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,30 @@ | ||||
| /* Derived from zlib fuzzers at http://github.com/google/oss-fuzz/tree/master/projects/zlib, | ||||
|  * see ossfuzz.sh for full license text. | ||||
| */ | ||||
|  | ||||
| #include <stddef.h> | ||||
| #include <stdint.h> | ||||
| #include <string.h> | ||||
|  | ||||
| #include "miniz.h" | ||||
|  | ||||
| int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) | ||||
| { | ||||
|     unsigned long int buffer_length = 1; | ||||
|     unsigned char *buffer = NULL; | ||||
|     int z_status = 0; | ||||
|  | ||||
|     if (size > 0) | ||||
|         buffer_length *= data[0]; | ||||
|     if (size > 1) | ||||
|         buffer_length *= data[1]; | ||||
|  | ||||
|     buffer = (unsigned char *)malloc(buffer_length); | ||||
|  | ||||
|     z_status = uncompress(buffer, &buffer_length, data, size); | ||||
|     free(buffer); | ||||
|  | ||||
|     if (Z_OK != z_status) | ||||
|         return 0; | ||||
|     return 0; | ||||
| } | ||||
							
								
								
									
										9
									
								
								tests/zip.dict
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										9
									
								
								tests/zip.dict
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,9 @@ | ||||
| # Fuzzing dictionary for .zip files | ||||
|  | ||||
| header_lfh="\x50\x4b\x03\x04" | ||||
| header_cd="\x50\x4b\x01\x02" | ||||
| header_eocd="\x50\x4b\x05\x06" | ||||
| header_eocd64="\x50\x4b\x06\x06" | ||||
| data_descriptor="\x50\x4b\x07\x08" | ||||
| extra_data_sig="\x50\x4b\x06\x08" | ||||
| digital_sig="\x50\x4b\x05\x05" | ||||
							
								
								
									
										57
									
								
								tests/zip_fuzzer.c
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										57
									
								
								tests/zip_fuzzer.c
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,57 @@ | ||||
| #include <stdint.h> | ||||
| #include <inttypes.h> | ||||
|  | ||||
| #include "miniz.h" | ||||
|  | ||||
| static char filename[260]; | ||||
| static unsigned char read_buf[1024 * 256]; | ||||
|  | ||||
| static const size_t filename_max = sizeof(filename); | ||||
| static const size_t read_buf_size = sizeof(read_buf); | ||||
| static const size_t data_max = 1024 * 256; | ||||
|  | ||||
| int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) | ||||
| { | ||||
|     if(size > data_max) return 0; | ||||
|  | ||||
|     int ret = 0; | ||||
|     mz_zip_archive zip; | ||||
|     mz_zip_zero_struct(&zip); | ||||
|  | ||||
|     mz_uint flags = 0; | ||||
|  | ||||
|     if(!mz_zip_reader_init_mem(&zip, data, size, flags)) return 0; | ||||
|  | ||||
|     mz_uint i, files; | ||||
|  | ||||
|     files = mz_zip_reader_get_num_files(&zip); | ||||
|  | ||||
|     for(i=0; i < files; i++) | ||||
|     { | ||||
|         mz_zip_clear_last_error(&zip); | ||||
|  | ||||
|         if(mz_zip_reader_is_file_a_directory(&zip, i)) continue; | ||||
|  | ||||
|         mz_zip_validate_file(&zip, i, MZ_ZIP_FLAG_VALIDATE_HEADERS_ONLY); | ||||
|  | ||||
|         if(mz_zip_reader_is_file_encrypted(&zip, i)) continue; | ||||
|  | ||||
|         mz_zip_clear_last_error(&zip); | ||||
|  | ||||
|         mz_uint ret = mz_zip_reader_get_filename(&zip, i, filename, filename_max); | ||||
|  | ||||
|         if(mz_zip_get_last_error(&zip)) continue; | ||||
|  | ||||
|         mz_zip_archive_file_stat file_stat = {0}; | ||||
|         mz_bool status = mz_zip_reader_file_stat(&zip, i, &file_stat) != 0; | ||||
|  | ||||
|         if ((file_stat.m_method) && (file_stat.m_method != MZ_DEFLATED)) continue; | ||||
|  | ||||
|         mz_zip_reader_extract_file_to_mem(&zip, file_stat.m_filename, read_buf, read_buf_size, 0); | ||||
|     } | ||||
|  | ||||
| cleanup: | ||||
|     mz_zip_reader_end(&zip); | ||||
|  | ||||
|     return ret; | ||||
| } | ||||
		Reference in New Issue
	
	Block a user