mirror of
				https://github.com/eledio-devices/thirdparty-miniz.git
				synced 2025-10-31 16:14:16 +01:00 
			
		
		
		
	Compare commits
	
		
			149 Commits
		
	
	
		
	
	| Author | SHA1 | Date | |
|---|---|---|---|
|  | 5a38f5564a | ||
|  | 9eedb97176 | ||
|  | 8a7cf60c7a | ||
|  | d9bd65a843 | ||
|  | 71ba5d12d6 | ||
|  | e285002431 | ||
|  | 842a20e586 | ||
|  | edc251cfa9 | ||
|  | 9ffbe56a73 | ||
|  | f2b59b344d | ||
|  | 0ce345c44a | ||
|  | 0796bdbee6 | ||
|  | 056cc8db14 | ||
|  | 60942b0f04 | ||
|  | 8997650f5c | ||
|  | 698faddd95 | ||
|  | ff862d4596 | ||
|  | 740049e643 | ||
|  | 2cd06e3f32 | ||
|  | f3d9e2293b | ||
|  | 1541a11e9b | ||
|  | 501a761549 | ||
|  | aa70ef1644 | ||
|  | 13b21dddc7 | ||
|  | a956b4c753 | ||
|  | ecbbbe0138 | ||
|  | 72e7267054 | ||
|  | 12b78b6d5a | ||
|  | 2beb69d0a5 | ||
|  | 0a88083589 | ||
|  | 3e5e488ba9 | ||
|  | 75c948a1dd | ||
|  | b4108c6fcf | ||
|  | e6a7c5daed | ||
|  | 66c7313326 | ||
|  | 82d6810a38 | ||
|  | ee4deb08fa | ||
|  | cb2b132b86 | ||
|  | 591faa9574 | ||
|  | 3a387ec369 | ||
|  | cda0b3e7f0 | ||
|  | e841503cad | ||
|  | a7961f5b4c | ||
|  | ca1a779ee1 | ||
|  | 18da352921 | ||
|  | d9c899cea4 | ||
|  | 70c79cc9d5 | ||
|  | 583f4f27c2 | ||
|  | 9b89689723 | ||
|  | f99eae6e04 | ||
|  | fc0c0f585e | ||
|  | 78ae375016 | ||
|  | f542e6df73 | ||
|  | 46347635c8 | ||
|  | c0aad72d46 | ||
|  | 08f2c2d7e3 | ||
|  | 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 | ||
|  | 49860a15fa | ||
|  | 524906517d | ||
|  | 3d000933a7 | ||
|  | 40b0612004 | ||
|  | 8da3cbb64e | ||
|  | 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 | 
							
								
								
									
										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 | ||||||
							
								
								
									
										3
									
								
								.gitignore
									
									
									
									
										vendored
									
									
										Normal file
									
								
							
							
						
						
									
										3
									
								
								.gitignore
									
									
									
									
										vendored
									
									
										Normal file
									
								
							| @@ -0,0 +1,3 @@ | |||||||
|  | /_build | ||||||
|  | /amalgamation | ||||||
|  | /bin | ||||||
							
								
								
									
										328
									
								
								CMakeLists.txt
									
									
									
									
									
								
							
							
						
						
									
										328
									
								
								CMakeLists.txt
									
									
									
									
									
								
							| @@ -1,5 +1,34 @@ | |||||||
| PROJECT(miniz C) | cmake_minimum_required(VERSION 3.0) | ||||||
| cmake_minimum_required(VERSION 2.8) |  | ||||||
|  | # 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) | ||||||
|  |   set(CMAKE_C_STANDARD 90) | ||||||
|  |   set(CMAKE_VERBOSE_MAKEFILE ON) | ||||||
|  |   # set(CMAKE_C_VISIBILITY_PRESET hidden) | ||||||
|  |   # set(CMAKE_VISIBILITY_INLINES_HIDDEN YES) | ||||||
|  |  | ||||||
|  |   if (MSVC) | ||||||
|  |     set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} /W3 /Zi /permissive-") | ||||||
|  |   else () | ||||||
|  |     set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wshadow -Wformat=2 -Wall -Wno-overlength-strings -pedantic") | ||||||
|  |   endif () | ||||||
|  | endif() | ||||||
|  |  | ||||||
|  | set(MINIZ_API_VERSION 3) | ||||||
|  | set(MINIZ_MINOR_VERSION 0) | ||||||
|  | set(MINIZ_PATCH_VERSION 0) | ||||||
|  | set(MINIZ_VERSION  | ||||||
|  |     ${MINIZ_API_VERSION}.${MINIZ_MINOR_VERSION}.${MINIZ_PATCH_VERSION}) | ||||||
|  |  | ||||||
| if(CMAKE_BUILD_TYPE STREQUAL "") | if(CMAKE_BUILD_TYPE STREQUAL "") | ||||||
|   # CMake defaults to leaving CMAKE_BUILD_TYPE empty. This screws up |   # CMake defaults to leaving CMAKE_BUILD_TYPE empty. This screws up | ||||||
|   # differentiation between debug and release builds. |   # differentiation between debug and release builds. | ||||||
| @@ -8,45 +37,268 @@ if(CMAKE_BUILD_TYPE STREQUAL "") | |||||||
| CMAKE_C_FLAGS used) Debug Release RelWithDebInfo MinSizeRel." FORCE) | CMAKE_C_FLAGS used) Debug Release RelWithDebInfo MinSizeRel." FORCE) | ||||||
| endif () | 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" OFF) | ||||||
|  | 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}) | if(INSTALL_PROJECT) | ||||||
| target_include_directories(miniz PUBLIC "${CMAKE_CURRENT_SOURCE_DIR}") |   include(GNUInstallDirs) | ||||||
|  |  | ||||||
| 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() | endif() | ||||||
|  |  | ||||||
| # add_executable(miniz_tester ${MINIZ_TESTER_SRC_LIST}) | if(BUILD_HEADER_ONLY) | ||||||
| # target_link_libraries(miniz_tester miniz) |   set(AMALGAMATE_SOURCES ON CACHE BOOL "Build a header-only version" FORCE) | ||||||
|  | endif(BUILD_HEADER_ONLY) | ||||||
|  |  | ||||||
| install(TARGETS ${PROJECT_NAME} EXPORT ${PROJECT_NAME}Targets | if(AMALGAMATE_SOURCES) | ||||||
|     ARCHIVE  DESTINATION lib |   # Amalgamate | ||||||
|     LIBRARY DESTINATION lib |   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 "#ifndef MINIZ_EXPORT\n#define MINIZ_EXPORT\n#endif\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) |   else(BUILD_HEADER_ONLY) | ||||||
| install(FILES ${INSTALL_HEADERS} DESTINATION include/${PROJECT_NAME}) |     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() | ||||||
|  |  | ||||||
|   | |||||||
							
								
								
									
										48
									
								
								ChangeLog.md
									
									
									
									
									
								
							
							
						
						
									
										48
									
								
								ChangeLog.md
									
									
									
									
									
								
							| @@ -1,5 +1,49 @@ | |||||||
| ## Changelog | ## Changelog | ||||||
|  |  | ||||||
|  | ### 3.0.0 | ||||||
|  |  | ||||||
|  |  - Reduce memory usage for inflate. This changes `struct tinfl_decompressor_tag` and therefore requires a major version bump | ||||||
|  |  - Add padding to structures so it continues to work if features differ. This also changes some structures | ||||||
|  |  - Use _ftelli64, _fseeki64 and stat with MinGW32 and OpenWatcom | ||||||
|  |  - Fix varios warnings with OpenWatcom compiler | ||||||
|  |  - Avoid using unaligned memory access in UBSan builds | ||||||
|  |  - Set MINIZ_LITTLE_ENDIAN only if not set | ||||||
|  |  - Add MINIZ_NO_DEFLATE_APIS and MINIZ_NO_INFLATE_APIS | ||||||
|  |  - Fix use of uninitialized memory in tinfl_decompress_mem_to_callback() | ||||||
|  |  - Use wfopen on windows | ||||||
|  |  - Use _wstat64 instead _stat64 on windows | ||||||
|  |  - Use level_and_flags after MZ_DEFAULT_COMPRESSION has been handled | ||||||
|  |  - Improve endianess detection | ||||||
|  |  - Don't use unaligned stores and loads per default | ||||||
|  |  - Fix function declaration if MINIZ_NO_STDIO is used | ||||||
|  |  - Fix MZ_ZIP_GENERAL_PURPOSE_BIT_FLAG_UTF8 not being set | ||||||
|  |  - Remove total files check (its 32-bit uint) | ||||||
|  |  - tinfl_decompress: avoid NULL ptr arithmetic UB | ||||||
|  |  - miniz_zip: fix mz_zip_reader_extract_to_heap to read correct sizes | ||||||
|  |  - Eliminate 64-bit operations on 32-bit machines | ||||||
|  |  - Disable treating warnings as error with MSVC | ||||||
|  |  - Disable building shared lib via CMake by default | ||||||
|  |   | ||||||
|  | ### 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 | ### 2.1.0 | ||||||
|  |  | ||||||
|  - More instances of memcpy instead of cast and use memcpy per default |  - More instances of memcpy instead of cast and use memcpy per default | ||||||
| @@ -82,7 +126,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. | - 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 |          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. |          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 |          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). |          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. |          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. | ||||||
| @@ -103,7 +147,7 @@ Merged over a few very minor bug fixes that I fixed in the zip64 branch. This is | |||||||
| Interim bugfix release while I work on the next major release with zip64 and streaming compression/decompression support. Fixed the MZ_ZIP_FLAG_DO_NOT_SORT_CENTRAL_DIRECTORY bug (thanks kahmyong.moon@hp.com), which could cause the locate files func to not find files when this flag was specified. Also fixed a bug in mz_zip_reader_extract_to_mem_no_alloc() with user provided read buffers (thanks kymoon). I also merged lots of compiler fixes from various github repo branches and Google Code issue reports. I finally added cmake support (only tested under for Linux so far), compiled and tested with clang v3.3 and gcc 4.6 (under Linux), added defl_write_image_to_png_file_in_memory_ex() (supports Y flipping for OpenGL use, real-time compression), added a new PNG example (example6.c - Mandelbrot), and I added 64-bit file I/O support (stat64(), etc.) for glibc. | Interim bugfix release while I work on the next major release with zip64 and streaming compression/decompression support. Fixed the MZ_ZIP_FLAG_DO_NOT_SORT_CENTRAL_DIRECTORY bug (thanks kahmyong.moon@hp.com), which could cause the locate files func to not find files when this flag was specified. Also fixed a bug in mz_zip_reader_extract_to_mem_no_alloc() with user provided read buffers (thanks kymoon). I also merged lots of compiler fixes from various github repo branches and Google Code issue reports. I finally added cmake support (only tested under for Linux so far), compiled and tested with clang v3.3 and gcc 4.6 (under Linux), added defl_write_image_to_png_file_in_memory_ex() (supports Y flipping for OpenGL use, real-time compression), added a new PNG example (example6.c - Mandelbrot), and I added 64-bit file I/O support (stat64(), etc.) for glibc. | ||||||
|  |  | ||||||
| - Critical fix for the MZ_ZIP_FLAG_DO_NOT_SORT_CENTRAL_DIRECTORY bug (thanks kahmyong.moon@hp.com) which could cause locate files to not find files. This bug | - Critical fix for the MZ_ZIP_FLAG_DO_NOT_SORT_CENTRAL_DIRECTORY bug (thanks kahmyong.moon@hp.com) which could cause locate files to not find files. This bug | ||||||
|         would only have occured in earlier versions if you explicitly used this flag, OR if you used mz_zip_extract_archive_file_to_heap() or mz_zip_add_mem_to_archive_file_in_place() |         would only have occurred in earlier versions if you explicitly used this flag, OR if you used mz_zip_extract_archive_file_to_heap() or mz_zip_add_mem_to_archive_file_in_place() | ||||||
|         (which used this flag). If you can't switch to v1.15 but want to fix this bug, just remove the uses of this flag from both helper funcs (and of course don't use the flag). |         (which used this flag). If you can't switch to v1.15 but want to fix this bug, just remove the uses of this flag from both helper funcs (and of course don't use the flag). | ||||||
| - Bugfix in mz_zip_reader_extract_to_mem_no_alloc() from kymoon when pUser_read_buf is not NULL and compressed size is > uncompressed size | - Bugfix in mz_zip_reader_extract_to_mem_no_alloc() from kymoon when pUser_read_buf is not NULL and compressed size is > uncompressed size | ||||||
| - Fixing mz_zip_reader_extract_*() funcs so they don't try to extract compressed data from directory entries, to account for weird zipfiles which contain zero-size compressed data on dir entries. | - Fixing mz_zip_reader_extract_*() funcs so they don't try to extract compressed data from directory entries, to account for weird zipfiles which contain zero-size compressed data on dir entries. | ||||||
|   | |||||||
							
								
								
									
										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,44 +3,30 @@ | |||||||
| set -e | set -e | ||||||
|  |  | ||||||
| mkdir -p amalgamation | mkdir -p amalgamation | ||||||
| OUTPUT_PREFIX=amalgamation/miniz |  | ||||||
|  |  | ||||||
| cat miniz.h > $OUTPUT_PREFIX.h | OUTPUT_PREFIX=_build/amalgamation | ||||||
| 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 |  | ||||||
|  |  | ||||||
|  | cmake -H. -B_build -DAMALGAMATE_SOURCES=ON -G"Unix Makefiles" | ||||||
| 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 |  | ||||||
|  |  | ||||||
| echo "int main() { return 0; }" > main.c | echo "int main() { return 0; }" > main.c | ||||||
| echo "Test compile with GCC..." | 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..." | 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 | if command -v clang | ||||||
| then | then | ||||||
| 		echo "Test compile with clang..." | 		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 | 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 | for def in MINIZ_NO_STDIO MINIZ_NO_TIME MINIZ_NO_DEFLATE_APIS MINIZ_NO_INFLATE_APIS MINIZ_NO_ARCHIVE_APIS MINIZ_NO_ARCHIVE_WRITING_APIS MINIZ_NO_ZLIB_APIS MINIZ_NO_ZLIB_COMPATIBLE_NAMES MINIZ_NO_MALLOC | ||||||
| do | do | ||||||
| 	echo "Test compile with GCC and define $def..." | 	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 | done | ||||||
| rm test.out | rm test.out | ||||||
| rm main.c | rm main.c | ||||||
|  |  | ||||||
|  | cp $OUTPUT_PREFIX/miniz.* amalgamation/ | ||||||
| cp ChangeLog.md amalgamation/ | cp ChangeLog.md amalgamation/ | ||||||
| cp LICENSE amalgamation/ | cp LICENSE amalgamation/ | ||||||
| cp readme.md amalgamation/ | cp readme.md amalgamation/ | ||||||
|   | |||||||
| @@ -13,7 +13,7 @@ | |||||||
| #endif | #endif | ||||||
|  |  | ||||||
| #include <stdio.h> | #include <stdio.h> | ||||||
| #include "miniz_zip.h" | #include "miniz.h" | ||||||
|  |  | ||||||
| typedef unsigned char uint8; | typedef unsigned char uint8; | ||||||
| typedef unsigned short uint16; | typedef unsigned short uint16; | ||||||
|   | |||||||
| @@ -100,7 +100,7 @@ int main(int argc, char *argv[]) | |||||||
|   file_loc = ftell(pInfile); |   file_loc = ftell(pInfile); | ||||||
|   fseek(pInfile, 0, SEEK_SET); |   fseek(pInfile, 0, SEEK_SET); | ||||||
|  |  | ||||||
|   if ((file_loc < 0) || (file_loc > INT_MAX)) |   if ((file_loc < 0) || ((mz_uint64)file_loc > INT_MAX)) | ||||||
|   { |   { | ||||||
|      // This is not a limitation of miniz or tinfl, but this example. |      // This is not a limitation of miniz or tinfl, but this example. | ||||||
|      printf("File is too large to be processed by this example.\n"); |      printf("File is too large to be processed by this example.\n"); | ||||||
|   | |||||||
| @@ -1,6 +1,6 @@ | |||||||
| // example4.c - Uses tinfl.c to decompress a zlib stream in memory to an output file | // 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. | // 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 <stdio.h> | ||||||
| #include <limits.h> | #include <limits.h> | ||||||
|  |  | ||||||
| @@ -47,7 +47,7 @@ int main(int argc, char *argv[]) | |||||||
|   file_loc = ftell(pInfile); |   file_loc = ftell(pInfile); | ||||||
|   fseek(pInfile, 0, SEEK_SET); |   fseek(pInfile, 0, SEEK_SET); | ||||||
|  |  | ||||||
|   if ((file_loc < 0) || (file_loc > INT_MAX)) |   if ((file_loc < 0) || ((mz_uint64)file_loc > INT_MAX)) | ||||||
|   { |   { | ||||||
|      // This is not a limitation of miniz or tinfl, but this example. |      // This is not a limitation of miniz or tinfl, but this example. | ||||||
|      printf("File is too large to be processed by this example.\n"); |      printf("File is too large to be processed by this example.\n"); | ||||||
|   | |||||||
| @@ -132,7 +132,7 @@ int main(int argc, char *argv[]) | |||||||
|    file_loc = ftell(pInfile); |    file_loc = ftell(pInfile); | ||||||
|    fseek(pInfile, 0, SEEK_SET); |    fseek(pInfile, 0, SEEK_SET); | ||||||
|  |  | ||||||
|    if ((file_loc < 0) || (file_loc > INT_MAX)) |    if ((file_loc < 0) || ((mz_uint64)file_loc > INT_MAX)) | ||||||
|    { |    { | ||||||
|       // This is not a limitation of miniz or tinfl, but this example. |       // This is not a limitation of miniz or tinfl, but this example. | ||||||
|       printf("File is too large to be processed by this example.\n"); |       printf("File is too large to be processed by this example.\n"); | ||||||
|   | |||||||
| @@ -34,27 +34,29 @@ static void hsv_to_rgb(int hue, int min, int max, rgb_t *p) | |||||||
|   if (!saturation) { |   if (!saturation) { | ||||||
|     p->r = p->g = p->b = 255 * (max - hue) / (max - min); |     p->r = p->g = p->b = 255 * (max - hue) / (max - min); | ||||||
|     return; |     return; | ||||||
|   } |   } else { | ||||||
|   double h = fmod(color_rotate + 1e-4 + 4.0 * (hue - min) / (max - min), 6); |     const double h_dbl = fmod(color_rotate + 1e-4 + 4.0 * (hue - min) / (max - min), 6); | ||||||
|   double c = 255.0f * saturation; |     const double c_dbl = 255 * saturation; | ||||||
|   double X = c * (1 - fabs(fmod(h, 2) - 1)); |     const double X_dbl = c_dbl * (1 - fabs(fmod(h_dbl, 2) - 1)); | ||||||
|  |     const int h = (int)h_dbl; | ||||||
|  |     const int c = (int)c_dbl; | ||||||
|  |     const int X = (int)X_dbl; | ||||||
|  |  | ||||||
|   p->r = p->g = p->b = 0; |     p->r = p->g = p->b = 0; | ||||||
|  |  | ||||||
|   switch((int)h) { |     switch(h) { | ||||||
|   case 0: p->r = c; p->g = X; return; |     case 0: p->r = c; p->g = X; return; | ||||||
|   case 1:	p->r = X; p->g = c; return; |     case 1:	p->r = X; p->g = c; return; | ||||||
|   case 2: p->g = c; p->b = X; return; |     case 2: p->g = c; p->b = X; return; | ||||||
|   case 3: p->g = X; p->b = c; return; |     case 3: p->g = X; p->b = c; return; | ||||||
|   case 4: p->r = X; p->b = c; return; |     case 4: p->r = X; p->b = c; return; | ||||||
|   default:p->r = c; p->b = X; |     default:p->r = c; p->b = X; | ||||||
|  |     } | ||||||
|   } |   } | ||||||
| } | } | ||||||
|  |  | ||||||
| int main(int argc, char *argv[]) | int main(int argc, char *argv[]) | ||||||
| { | { | ||||||
|   (void)argc, (void)argv; |  | ||||||
|  |  | ||||||
|   // Image resolution |   // Image resolution | ||||||
|   const int iXmax = 4096; |   const int iXmax = 4096; | ||||||
|   const int iYmax = 4096; |   const int iYmax = 4096; | ||||||
| @@ -89,6 +91,8 @@ int main(int argc, char *argv[]) | |||||||
|  |  | ||||||
|   int MinIter = 9999, MaxIter = 0; |   int MinIter = 9999, MaxIter = 0; | ||||||
|  |  | ||||||
|  |   (void)argc, (void)argv; | ||||||
|  |  | ||||||
|   for(iY = 0; iY < iYmax; iY++) |   for(iY = 0; iY < iYmax; iY++) | ||||||
|   { |   { | ||||||
|     Cy = CyMin + iY * PixelHeight; |     Cy = CyMin + iY * PixelHeight; | ||||||
| @@ -134,7 +138,7 @@ int main(int argc, char *argv[]) | |||||||
|  |  | ||||||
|       uint Iterations = color[0] | (color[1] << 8U); |       uint Iterations = color[0] | (color[1] << 8U); | ||||||
|  |  | ||||||
|       hsv_to_rgb(Iterations, MinIter, MaxIter, (rgb_t *)color); |       hsv_to_rgb((int)Iterations, MinIter, MaxIter, (rgb_t *)color); | ||||||
|     } |     } | ||||||
|   } |   } | ||||||
|  |  | ||||||
|   | |||||||
							
								
								
									
										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 | ||||||
							
								
								
									
										35
									
								
								miniz.c
									
									
									
									
									
								
							
							
						
						
									
										35
									
								
								miniz.c
									
									
									
									
									
								
							| @@ -82,6 +82,12 @@ mz_ulong mz_adler32(mz_ulong adler, const unsigned char *ptr, size_t buf_len) | |||||||
|         } |         } | ||||||
|         return ~crcu32; |         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 | #else | ||||||
| /* Faster, but larger CPU cache footprint. | /* Faster, but larger CPU cache footprint. | ||||||
|  */ |  */ | ||||||
| @@ -157,17 +163,17 @@ void mz_free(void *p) | |||||||
|     MZ_FREE(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; |     (void)opaque, (void)items, (void)size; | ||||||
|     return MZ_MALLOC(items * 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; |     (void)opaque, (void)address; | ||||||
|     MZ_FREE(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; |     (void)opaque, (void)address, (void)items, (void)size; | ||||||
|     return MZ_REALLOC(address, items * size); |     return MZ_REALLOC(address, items * size); | ||||||
| @@ -180,6 +186,8 @@ const char *mz_version(void) | |||||||
|  |  | ||||||
| #ifndef MINIZ_NO_ZLIB_APIS | #ifndef MINIZ_NO_ZLIB_APIS | ||||||
|  |  | ||||||
|  | #ifndef MINIZ_NO_DEFLATE_APIS | ||||||
|  |  | ||||||
| int mz_deflateInit(mz_streamp pStream, int level) | int mz_deflateInit(mz_streamp pStream, int level) | ||||||
| { | { | ||||||
|     return mz_deflateInit2(pStream, level, MZ_DEFLATED, MZ_DEFAULT_WINDOW_BITS, 9, MZ_DEFAULT_STRATEGY); |     return mz_deflateInit2(pStream, level, MZ_DEFLATED, MZ_DEFAULT_WINDOW_BITS, 9, MZ_DEFAULT_STRATEGY); | ||||||
| @@ -314,7 +322,7 @@ int mz_compress2(unsigned char *pDest, mz_ulong *pDest_len, const unsigned char | |||||||
|     memset(&stream, 0, sizeof(stream)); |     memset(&stream, 0, sizeof(stream)); | ||||||
|  |  | ||||||
|     /* In case mz_ulong is 64-bits (argh I hate longs). */ |     /* In case mz_ulong is 64-bits (argh I hate longs). */ | ||||||
|     if ((source_len | *pDest_len) > 0xFFFFFFFFU) |     if ((mz_uint64)(source_len | *pDest_len) > 0xFFFFFFFFU) | ||||||
|         return MZ_PARAM_ERROR; |         return MZ_PARAM_ERROR; | ||||||
|  |  | ||||||
|     stream.next_in = pSource; |     stream.next_in = pSource; | ||||||
| @@ -347,6 +355,10 @@ mz_ulong mz_compressBound(mz_ulong source_len) | |||||||
|     return mz_deflateBound(NULL, source_len); |     return mz_deflateBound(NULL, source_len); | ||||||
| } | } | ||||||
|  |  | ||||||
|  | #endif /*#ifndef MINIZ_NO_DEFLATE_APIS*/ | ||||||
|  |  | ||||||
|  | #ifndef MINIZ_NO_INFLATE_APIS | ||||||
|  |  | ||||||
| typedef struct | typedef struct | ||||||
| { | { | ||||||
|     tinfl_decompressor m_decomp; |     tinfl_decompressor m_decomp; | ||||||
| @@ -546,19 +558,18 @@ int mz_inflateEnd(mz_streamp pStream) | |||||||
|     } |     } | ||||||
|     return MZ_OK; |     return MZ_OK; | ||||||
| } | } | ||||||
|  | int mz_uncompress2(unsigned char *pDest, mz_ulong *pDest_len, const unsigned char *pSource, mz_ulong *pSource_len) | ||||||
| int mz_uncompress(unsigned char *pDest, mz_ulong *pDest_len, const unsigned char *pSource, mz_ulong source_len) |  | ||||||
| { | { | ||||||
|     mz_stream stream; |     mz_stream stream; | ||||||
|     int status; |     int status; | ||||||
|     memset(&stream, 0, sizeof(stream)); |     memset(&stream, 0, sizeof(stream)); | ||||||
|  |  | ||||||
|     /* In case mz_ulong is 64-bits (argh I hate longs). */ |     /* In case mz_ulong is 64-bits (argh I hate longs). */ | ||||||
|     if ((source_len | *pDest_len) > 0xFFFFFFFFU) |     if ((mz_uint64)(*pSource_len | *pDest_len) > 0xFFFFFFFFU) | ||||||
|         return MZ_PARAM_ERROR; |         return MZ_PARAM_ERROR; | ||||||
|  |  | ||||||
|     stream.next_in = pSource; |     stream.next_in = pSource; | ||||||
|     stream.avail_in = (mz_uint32)source_len; |     stream.avail_in = (mz_uint32)*pSource_len; | ||||||
|     stream.next_out = pDest; |     stream.next_out = pDest; | ||||||
|     stream.avail_out = (mz_uint32)*pDest_len; |     stream.avail_out = (mz_uint32)*pDest_len; | ||||||
|  |  | ||||||
| @@ -567,6 +578,7 @@ int mz_uncompress(unsigned char *pDest, mz_ulong *pDest_len, const unsigned char | |||||||
|         return status; |         return status; | ||||||
|  |  | ||||||
|     status = mz_inflate(&stream, MZ_FINISH); |     status = mz_inflate(&stream, MZ_FINISH); | ||||||
|  |     *pSource_len = *pSource_len - stream.avail_in; | ||||||
|     if (status != MZ_STREAM_END) |     if (status != MZ_STREAM_END) | ||||||
|     { |     { | ||||||
|         mz_inflateEnd(&stream); |         mz_inflateEnd(&stream); | ||||||
| @@ -577,6 +589,13 @@ int mz_uncompress(unsigned char *pDest, mz_ulong *pDest_len, const unsigned char | |||||||
|     return mz_inflateEnd(&stream); |     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); | ||||||
|  | } | ||||||
|  |  | ||||||
|  | #endif /*#ifndef MINIZ_NO_INFLATE_APIS*/ | ||||||
|  |  | ||||||
| const char *mz_error(int err) | const char *mz_error(int err) | ||||||
| { | { | ||||||
|     static struct |     static struct | ||||||
|   | |||||||
							
								
								
									
										121
									
								
								miniz.h
									
									
									
									
									
								
							
							
						
						
									
										121
									
								
								miniz.h
									
									
									
									
									
								
							| @@ -1,4 +1,4 @@ | |||||||
| /* miniz.c 2.1.0 - public domain deflate/inflate, zlib-subset, ZIP reading/writing/appending, PNG writing | /* miniz.c 3.0.0 - public domain deflate/inflate, zlib-subset, ZIP reading/writing/appending, PNG writing | ||||||
|    See "unlicense" statement at the end of this file. |    See "unlicense" statement at the end of this file. | ||||||
|    Rich Geldreich <richgel99@gmail.com>, last updated Oct. 13, 2013 |    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 |    Implements RFC 1950: http://www.ietf.org/rfc/rfc1950.txt and RFC 1951: http://www.ietf.org/rfc/rfc1951.txt | ||||||
| @@ -95,7 +95,7 @@ | |||||||
|      possibility that the archive's central directory could be lost with this method if anything goes wrong, though. |      possibility that the archive's central directory could be lost with this method if anything goes wrong, though. | ||||||
|  |  | ||||||
|      - ZIP archive support limitations: |      - 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. |      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 |    * This is a header file library, like stb_image.c. To get only a header file, either cut and paste the | ||||||
| @@ -112,12 +112,10 @@ | |||||||
| */ | */ | ||||||
| #pragma once | #pragma once | ||||||
|  |  | ||||||
| #include "miniz_common.h" | #include "miniz_export.h" | ||||||
| #include "miniz_tdef.h" |  | ||||||
| #include "miniz_tinfl.h" |  | ||||||
|  |  | ||||||
| /* Defines to completely disable specific portions of miniz.c:  | /* 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. */ |    If all macros here are defined the only functionality remaining will be CRC-32 and adler-32. */ | ||||||
|  |  | ||||||
| /* Define MINIZ_NO_STDIO to disable all usage and any functions which rely on stdio for file I/O. */ | /* Define MINIZ_NO_STDIO to disable all usage and any functions which rely on stdio for file I/O. */ | ||||||
| /*#define MINIZ_NO_STDIO */ | /*#define MINIZ_NO_STDIO */ | ||||||
| @@ -127,6 +125,12 @@ | |||||||
| /* The current downside is the times written to your archives will be from 1979. */ | /* The current downside is the times written to your archives will be from 1979. */ | ||||||
| /*#define MINIZ_NO_TIME */ | /*#define MINIZ_NO_TIME */ | ||||||
|  |  | ||||||
|  | /* Define MINIZ_NO_DEFLATE_APIS to disable all compression API's. */ | ||||||
|  | /*#define MINIZ_NO_DEFLATE_APIS */ | ||||||
|  |  | ||||||
|  | /* Define MINIZ_NO_INFLATE_APIS to disable all decompression API's. */ | ||||||
|  | /*#define MINIZ_NO_INFLATE_APIS */ | ||||||
|  |  | ||||||
| /* Define MINIZ_NO_ARCHIVE_APIS to disable all ZIP archive API's. */ | /* Define MINIZ_NO_ARCHIVE_APIS to disable all ZIP archive API's. */ | ||||||
| /*#define MINIZ_NO_ARCHIVE_APIS */ | /*#define MINIZ_NO_ARCHIVE_APIS */ | ||||||
|  |  | ||||||
| @@ -145,6 +149,14 @@ | |||||||
|    functions (such as tdefl_compress_mem_to_heap() and tinfl_decompress_mem_to_heap()) won't work. */ |    functions (such as tdefl_compress_mem_to_heap() and tinfl_decompress_mem_to_heap()) won't work. */ | ||||||
| /*#define MINIZ_NO_MALLOC */ | /*#define MINIZ_NO_MALLOC */ | ||||||
|  |  | ||||||
|  | #ifdef MINIZ_NO_INFLATE_APIS | ||||||
|  | #define MINIZ_NO_ARCHIVE_APIS | ||||||
|  | #endif | ||||||
|  |  | ||||||
|  | #ifdef MINIZ_NO_DEFLATE_APIS | ||||||
|  | #define MINIZ_NO_ARCHIVE_WRITING_APIS | ||||||
|  | #endif | ||||||
|  |  | ||||||
| #if defined(__TINYC__) && (defined(__linux) || defined(__linux__)) | #if defined(__TINYC__) && (defined(__linux) || defined(__linux__)) | ||||||
| /* TODO: Work around "error: include file 'sys\utime.h' when compiling with tcc on Linux */ | /* TODO: Work around "error: include file 'sys\utime.h' when compiling with tcc on Linux */ | ||||||
| #define MINIZ_NO_TIME | #define MINIZ_NO_TIME | ||||||
| @@ -163,18 +175,40 @@ | |||||||
| #define MINIZ_X86_OR_X64_CPU 0 | #define MINIZ_X86_OR_X64_CPU 0 | ||||||
| #endif | #endif | ||||||
|  |  | ||||||
| #if (__BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__) || MINIZ_X86_OR_X64_CPU | /* Set MINIZ_LITTLE_ENDIAN only if not set */ | ||||||
|  | #if !defined(MINIZ_LITTLE_ENDIAN) | ||||||
|  | #if defined(__BYTE_ORDER__) && defined(__ORDER_LITTLE_ENDIAN__) | ||||||
|  |  | ||||||
|  | #if (__BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__) | ||||||
| /* Set MINIZ_LITTLE_ENDIAN to 1 if the processor is little endian. */ | /* Set MINIZ_LITTLE_ENDIAN to 1 if the processor is little endian. */ | ||||||
| #define MINIZ_LITTLE_ENDIAN 1 | #define MINIZ_LITTLE_ENDIAN 1 | ||||||
| #else | #else | ||||||
| #define MINIZ_LITTLE_ENDIAN 0 | #define MINIZ_LITTLE_ENDIAN 0 | ||||||
| #endif | #endif | ||||||
|  |  | ||||||
|  | #else | ||||||
|  |  | ||||||
|  | #if MINIZ_X86_OR_X64_CPU | ||||||
|  | #define MINIZ_LITTLE_ENDIAN 1 | ||||||
|  | #else | ||||||
|  | #define MINIZ_LITTLE_ENDIAN 0 | ||||||
|  | #endif | ||||||
|  |  | ||||||
|  | #endif | ||||||
|  | #endif | ||||||
|  |  | ||||||
|  | /* Using unaligned loads and stores causes errors when using UBSan */ | ||||||
|  | #if defined(__has_feature) | ||||||
|  | #if __has_feature(undefined_behavior_sanitizer) | ||||||
|  | #define MINIZ_USE_UNALIGNED_LOADS_AND_STORES 0 | ||||||
|  | #endif | ||||||
|  | #endif | ||||||
|  |  | ||||||
| /* Set MINIZ_USE_UNALIGNED_LOADS_AND_STORES only if not set */ | /* Set MINIZ_USE_UNALIGNED_LOADS_AND_STORES only if not set */ | ||||||
| #if !defined(MINIZ_USE_UNALIGNED_LOADS_AND_STORES) | #if !defined(MINIZ_USE_UNALIGNED_LOADS_AND_STORES) | ||||||
| #if MINIZ_X86_OR_X64_CPU | #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. */ | /* 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_USE_UNALIGNED_LOADS_AND_STORES 0 | ||||||
| #define MINIZ_UNALIGNED_USE_MEMCPY | #define MINIZ_UNALIGNED_USE_MEMCPY | ||||||
| #else | #else | ||||||
| #define MINIZ_USE_UNALIGNED_LOADS_AND_STORES 0 | #define MINIZ_USE_UNALIGNED_LOADS_AND_STORES 0 | ||||||
| @@ -198,15 +232,15 @@ extern "C" { | |||||||
| typedef unsigned long mz_ulong; | 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. */ | /* 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) | #define MZ_ADLER32_INIT (1) | ||||||
| /* mz_adler32() returns the initial adler-32 value to use when called with ptr==NULL. */ | /* 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) | #define MZ_CRC32_INIT (0) | ||||||
| /* mz_crc32() returns the initial CRC-32 value to use when called with ptr==NULL. */ | /* 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. */ | /* Compression strategies. */ | ||||||
| enum | enum | ||||||
| @@ -222,7 +256,7 @@ enum | |||||||
| #define MZ_DEFLATED 8 | #define MZ_DEFLATED 8 | ||||||
|  |  | ||||||
| /* Heap allocation callbacks. | /* 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_alloc_func)(void *opaque, size_t items, size_t size); | ||||||
| typedef void (*mz_free_func)(void *opaque, void *address); | typedef void (*mz_free_func)(void *opaque, void *address); | ||||||
| typedef void *(*mz_realloc_func)(void *opaque, void *address, size_t items, size_t size); | typedef void *(*mz_realloc_func)(void *opaque, void *address, size_t items, size_t size); | ||||||
| @@ -238,10 +272,10 @@ enum | |||||||
|     MZ_DEFAULT_COMPRESSION = -1 |     MZ_DEFAULT_COMPRESSION = -1 | ||||||
| }; | }; | ||||||
|  |  | ||||||
| #define MZ_VERSION "10.1.0" | #define MZ_VERSION "11.0.0" | ||||||
| #define MZ_VERNUM 0xA100 | #define MZ_VERNUM 0xB000 | ||||||
| #define MZ_VER_MAJOR 10 | #define MZ_VER_MAJOR 11 | ||||||
| #define MZ_VER_MINOR 1 | #define MZ_VER_MINOR 0 | ||||||
| #define MZ_VER_REVISION 0 | #define MZ_VER_REVISION 0 | ||||||
| #define MZ_VER_SUBREVISION 0 | #define MZ_VER_SUBREVISION 0 | ||||||
|  |  | ||||||
| @@ -304,7 +338,9 @@ typedef struct mz_stream_s | |||||||
| typedef mz_stream *mz_streamp; | typedef mz_stream *mz_streamp; | ||||||
|  |  | ||||||
| /* Returns the version string of miniz.c. */ | /* Returns the version string of miniz.c. */ | ||||||
| const char *mz_version(void); | MINIZ_EXPORT const char *mz_version(void); | ||||||
|  |  | ||||||
|  | #ifndef MINIZ_NO_DEFLATE_APIS | ||||||
|  |  | ||||||
| /* mz_deflateInit() initializes a compressor with default options: */ | /* mz_deflateInit() initializes a compressor with default options: */ | ||||||
| /* Parameters: */ | /* Parameters: */ | ||||||
| @@ -317,17 +353,17 @@ const char *mz_version(void); | |||||||
| /*  MZ_STREAM_ERROR if the stream is bogus. */ | /*  MZ_STREAM_ERROR if the stream is bogus. */ | ||||||
| /*  MZ_PARAM_ERROR if the input parameters are bogus. */ | /*  MZ_PARAM_ERROR if the input parameters are bogus. */ | ||||||
| /*  MZ_MEM_ERROR on out of memory. */ | /*  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: */ | /* mz_deflateInit2() is like mz_deflate(), except with more control: */ | ||||||
| /* Additional parameters: */ | /* Additional parameters: */ | ||||||
| /*   method must be MZ_DEFLATED */ | /*   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) */ | /*   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) */ | /*   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(). */ | /* 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. */ | /* mz_deflate() compresses the input to output, consuming as much of the input and producing as much output as possible. */ | ||||||
| /* Parameters: */ | /* Parameters: */ | ||||||
| @@ -339,34 +375,38 @@ int mz_deflateReset(mz_streamp pStream); | |||||||
| /*   MZ_STREAM_ERROR if the stream is bogus. */ | /*   MZ_STREAM_ERROR if the stream is bogus. */ | ||||||
| /*   MZ_PARAM_ERROR if one of the parameters is invalid. */ | /*   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.) */ | /*   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: */ | /* mz_deflateEnd() deinitializes a compressor: */ | ||||||
| /* Return values: */ | /* Return values: */ | ||||||
| /*  MZ_OK on success. */ | /*  MZ_OK on success. */ | ||||||
| /*  MZ_STREAM_ERROR if the stream is bogus. */ | /*  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_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(): */ | /* 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. */ | /* 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); | MINIZ_EXPORT 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_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_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); | ||||||
|  |  | ||||||
|  | #endif /*#ifndef MINIZ_NO_DEFLATE_APIS*/ | ||||||
|  |  | ||||||
|  | #ifndef MINIZ_NO_INFLATE_APIS | ||||||
|  |  | ||||||
| /* Initializes a decompressor. */ | /* 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: */ | /* 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). */ | /* 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(). */ | /* Quickly resets a compressor without having to reallocate anything. Same as calling mz_inflateEnd() followed by mz_inflateInit()/mz_inflateInit2(). */ | ||||||
| int mz_inflateReset(mz_streamp pStream); | 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. */ | /* 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: */ | /* Parameters: */ | ||||||
| @@ -382,17 +422,19 @@ int mz_inflateReset(mz_streamp pStream); | |||||||
| /*   MZ_PARAM_ERROR if one of the parameters is invalid. */ | /*   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 */ | /*   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). */ | /*   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. */ | /* Deinitializes a decompressor. */ | ||||||
| int mz_inflateEnd(mz_streamp pStream); | MINIZ_EXPORT int mz_inflateEnd(mz_streamp pStream); | ||||||
|  |  | ||||||
| /* Single-call decompression. */ | /* Single-call decompression. */ | ||||||
| /* Returns MZ_OK on success, or one of the error codes from mz_inflate() on failure. */ | /* 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); | ||||||
|  | #endif /*#ifndef MINIZ_NO_INFLATE_APIS*/ | ||||||
|  |  | ||||||
| /* Returns a string description of the specified error code, or NULL if the error code is invalid. */ | /* 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. */ | /* 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. */ | /* Define MINIZ_NO_ZLIB_COMPATIBLE_NAMES to disable zlib-compatibility if you use zlib in the same project. */ | ||||||
| @@ -440,6 +482,8 @@ typedef void *const voidpc; | |||||||
| #define free_func mz_free_func | #define free_func mz_free_func | ||||||
| #define internal_state mz_internal_state | #define internal_state mz_internal_state | ||||||
| #define z_stream mz_stream | #define z_stream mz_stream | ||||||
|  |  | ||||||
|  | #ifndef MINIZ_NO_DEFLATE_APIS | ||||||
| #define deflateInit mz_deflateInit | #define deflateInit mz_deflateInit | ||||||
| #define deflateInit2 mz_deflateInit2 | #define deflateInit2 mz_deflateInit2 | ||||||
| #define deflateReset mz_deflateReset | #define deflateReset mz_deflateReset | ||||||
| @@ -449,12 +493,18 @@ typedef void *const voidpc; | |||||||
| #define compress mz_compress | #define compress mz_compress | ||||||
| #define compress2 mz_compress2 | #define compress2 mz_compress2 | ||||||
| #define compressBound mz_compressBound | #define compressBound mz_compressBound | ||||||
|  | #endif /*#ifndef MINIZ_NO_DEFLATE_APIS*/ | ||||||
|  |  | ||||||
|  | #ifndef MINIZ_NO_INFLATE_APIS | ||||||
| #define inflateInit mz_inflateInit | #define inflateInit mz_inflateInit | ||||||
| #define inflateInit2 mz_inflateInit2 | #define inflateInit2 mz_inflateInit2 | ||||||
| #define inflateReset mz_inflateReset | #define inflateReset mz_inflateReset | ||||||
| #define inflate mz_inflate | #define inflate mz_inflate | ||||||
| #define inflateEnd mz_inflateEnd | #define inflateEnd mz_inflateEnd | ||||||
| #define uncompress mz_uncompress | #define uncompress mz_uncompress | ||||||
|  | #define uncompress2 mz_uncompress2 | ||||||
|  | #endif /*#ifndef MINIZ_NO_INFLATE_APIS*/ | ||||||
|  |  | ||||||
| #define crc32 mz_crc32 | #define crc32 mz_crc32 | ||||||
| #define adler32 mz_adler32 | #define adler32 mz_adler32 | ||||||
| #define MAX_WBITS 15 | #define MAX_WBITS 15 | ||||||
| @@ -475,3 +525,8 @@ typedef void *const voidpc; | |||||||
| #ifdef __cplusplus | #ifdef __cplusplus | ||||||
| } | } | ||||||
| #endif | #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 <stdlib.h> | ||||||
| #include <string.h> | #include <string.h> | ||||||
|  |  | ||||||
|  | #include "miniz_export.h" | ||||||
|  |  | ||||||
| /* ------------------- Types and macros */ | /* ------------------- Types and macros */ | ||||||
| typedef unsigned char mz_uint8; | typedef unsigned char mz_uint8; | ||||||
| typedef signed short mz_int16; | typedef signed short mz_int16; | ||||||
| @@ -34,7 +36,8 @@ typedef int mz_bool; | |||||||
| #ifdef MINIZ_NO_TIME | #ifdef MINIZ_NO_TIME | ||||||
| typedef struct mz_dummy_time_t_tag | typedef struct mz_dummy_time_t_tag | ||||||
| { | { | ||||||
|     int m_dummy; |     mz_uint32 m_dummy1; | ||||||
|  |     mz_uint32 m_dummy2; | ||||||
| } mz_dummy_time_t; | } mz_dummy_time_t; | ||||||
| #define MZ_TIME_T mz_dummy_time_t | #define MZ_TIME_T mz_dummy_time_t | ||||||
| #else | #else | ||||||
| @@ -56,6 +59,8 @@ typedef struct mz_dummy_time_t_tag | |||||||
| #define MZ_MAX(a, b) (((a) > (b)) ? (a) : (b)) | #define MZ_MAX(a, b) (((a) > (b)) ? (a) : (b)) | ||||||
| #define MZ_MIN(a, b) (((a) < (b)) ? (a) : (b)) | #define MZ_MIN(a, b) (((a) < (b)) ? (a) : (b)) | ||||||
| #define MZ_CLEAR_OBJ(obj) memset(&(obj), 0, sizeof(obj)) | #define MZ_CLEAR_OBJ(obj) memset(&(obj), 0, sizeof(obj)) | ||||||
|  | #define MZ_CLEAR_ARR(obj) memset((obj), 0, sizeof(obj)) | ||||||
|  | #define MZ_CLEAR_PTR(obj) memset((obj), 0, sizeof(*obj)) | ||||||
|  |  | ||||||
| #if MINIZ_USE_UNALIGNED_LOADS_AND_STORES && MINIZ_LITTLE_ENDIAN | #if MINIZ_USE_UNALIGNED_LOADS_AND_STORES && MINIZ_LITTLE_ENDIAN | ||||||
| #define MZ_READ_LE16(p) *((const mz_uint16 *)(p)) | #define MZ_READ_LE16(p) *((const mz_uint16 *)(p)) | ||||||
| @@ -79,9 +84,9 @@ typedef struct mz_dummy_time_t_tag | |||||||
| extern "C" { | extern "C" { | ||||||
| #endif | #endif | ||||||
|  |  | ||||||
| extern void *miniz_def_alloc_func(void *opaque, size_t items, size_t size); | extern MINIZ_EXPORT void *miniz_def_alloc_func(void *opaque, size_t items, size_t size); | ||||||
| extern void miniz_def_free_func(void *opaque, void *address); | extern MINIZ_EXPORT 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_realloc_func(void *opaque, void *address, size_t items, size_t size); | ||||||
|  |  | ||||||
| #define MZ_UINT16_MAX (0xFFFFU) | #define MZ_UINT16_MAX (0xFFFFU) | ||||||
| #define MZ_UINT32_MAX (0xFFFFFFFFU) | #define MZ_UINT32_MAX (0xFFFFFFFFU) | ||||||
|   | |||||||
							
								
								
									
										30
									
								
								miniz_tdef.c
									
									
									
									
									
								
							
							
						
						
									
										30
									
								
								miniz_tdef.c
									
									
									
									
									
								
							| @@ -24,9 +24,10 @@ | |||||||
|  * |  * | ||||||
|  **************************************************************************/ |  **************************************************************************/ | ||||||
|  |  | ||||||
| #include "miniz_tdef.h" |  | ||||||
| #include "miniz.h" | #include "miniz.h" | ||||||
|  |  | ||||||
|  | #ifndef MINIZ_NO_DEFLATE_APIS | ||||||
|  |  | ||||||
| #ifdef __cplusplus | #ifdef __cplusplus | ||||||
| extern "C" { | extern "C" { | ||||||
| #endif | #endif | ||||||
| @@ -105,7 +106,7 @@ static tdefl_sym_freq *tdefl_radix_sort_syms(mz_uint num_syms, tdefl_sym_freq *p | |||||||
| { | { | ||||||
|     mz_uint32 total_passes = 2, pass_shift, pass, i, hist[256 * 2]; |     mz_uint32 total_passes = 2, pass_shift, pass, i, hist[256 * 2]; | ||||||
|     tdefl_sym_freq *pCur_syms = pSyms0, *pNew_syms = pSyms1; |     tdefl_sym_freq *pCur_syms = pSyms0, *pNew_syms = pSyms1; | ||||||
|     MZ_CLEAR_OBJ(hist); |     MZ_CLEAR_ARR(hist); | ||||||
|     for (i = 0; i < num_syms; i++) |     for (i = 0; i < num_syms; i++) | ||||||
|     { |     { | ||||||
|         mz_uint freq = pSyms0[i].m_key; |         mz_uint freq = pSyms0[i].m_key; | ||||||
| @@ -223,7 +224,7 @@ static void tdefl_optimize_huffman_table(tdefl_compressor *d, int table_num, int | |||||||
| { | { | ||||||
|     int i, j, l, num_codes[1 + TDEFL_MAX_SUPPORTED_HUFF_CODESIZE]; |     int i, j, l, num_codes[1 + TDEFL_MAX_SUPPORTED_HUFF_CODESIZE]; | ||||||
|     mz_uint next_code[TDEFL_MAX_SUPPORTED_HUFF_CODESIZE + 1]; |     mz_uint next_code[TDEFL_MAX_SUPPORTED_HUFF_CODESIZE + 1]; | ||||||
|     MZ_CLEAR_OBJ(num_codes); |     MZ_CLEAR_ARR(num_codes); | ||||||
|     if (static_table) |     if (static_table) | ||||||
|     { |     { | ||||||
|         for (i = 0; i < table_len; i++) |         for (i = 0; i < table_len; i++) | ||||||
| @@ -249,8 +250,8 @@ static void tdefl_optimize_huffman_table(tdefl_compressor *d, int table_num, int | |||||||
|  |  | ||||||
|         tdefl_huffman_enforce_max_code_size(num_codes, num_used_syms, code_size_limit); |         tdefl_huffman_enforce_max_code_size(num_codes, num_used_syms, code_size_limit); | ||||||
|  |  | ||||||
|         MZ_CLEAR_OBJ(d->m_huff_code_sizes[table_num]); |         MZ_CLEAR_ARR(d->m_huff_code_sizes[table_num]); | ||||||
|         MZ_CLEAR_OBJ(d->m_huff_codes[table_num]); |         MZ_CLEAR_ARR(d->m_huff_codes[table_num]); | ||||||
|         for (i = 1, j = num_used_syms; i <= code_size_limit; i++) |         for (i = 1, j = num_used_syms; i <= code_size_limit; i++) | ||||||
|             for (l = num_codes[i]; l > 0; l--) |             for (l = num_codes[i]; l > 0; l--) | ||||||
|                 d->m_huff_code_sizes[table_num][pSyms[--j].m_sym_index] = (mz_uint8)(i); |                 d->m_huff_code_sizes[table_num][pSyms[--j].m_sym_index] = (mz_uint8)(i); | ||||||
| @@ -1075,9 +1076,7 @@ static MZ_FORCEINLINE void tdefl_record_match(tdefl_compressor *d, mz_uint match | |||||||
|     s0 = s_tdefl_small_dist_sym[match_dist & 511]; |     s0 = s_tdefl_small_dist_sym[match_dist & 511]; | ||||||
|     s1 = s_tdefl_large_dist_sym[(match_dist >> 8) & 127]; |     s1 = s_tdefl_large_dist_sym[(match_dist >> 8) & 127]; | ||||||
|     d->m_huff_count[1][(match_dist < 512) ? s0 : s1]++; |     d->m_huff_count[1][(match_dist < 512) ? s0 : s1]++; | ||||||
|  |     d->m_huff_count[0][s_tdefl_len_sym[match_len - TDEFL_MIN_MATCH_LEN]]++; | ||||||
|     if (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) | static mz_bool tdefl_compress_normal(tdefl_compressor *d) | ||||||
| @@ -1095,7 +1094,7 @@ static mz_bool tdefl_compress_normal(tdefl_compressor *d) | |||||||
|             mz_uint dst_pos = (d->m_lookahead_pos + d->m_lookahead_size) & TDEFL_LZ_DICT_SIZE_MASK, ins_pos = d->m_lookahead_pos + d->m_lookahead_size - 2; |             mz_uint dst_pos = (d->m_lookahead_pos + d->m_lookahead_size) & TDEFL_LZ_DICT_SIZE_MASK, ins_pos = d->m_lookahead_pos + d->m_lookahead_size - 2; | ||||||
|             mz_uint hash = (d->m_dict[ins_pos & TDEFL_LZ_DICT_SIZE_MASK] << TDEFL_LZ_HASH_SHIFT) ^ d->m_dict[(ins_pos + 1) & TDEFL_LZ_DICT_SIZE_MASK]; |             mz_uint hash = (d->m_dict[ins_pos & TDEFL_LZ_DICT_SIZE_MASK] << TDEFL_LZ_HASH_SHIFT) ^ d->m_dict[(ins_pos + 1) & TDEFL_LZ_DICT_SIZE_MASK]; | ||||||
|             mz_uint num_bytes_to_process = (mz_uint)MZ_MIN(src_buf_left, TDEFL_MAX_MATCH_LEN - d->m_lookahead_size); |             mz_uint num_bytes_to_process = (mz_uint)MZ_MIN(src_buf_left, TDEFL_MAX_MATCH_LEN - d->m_lookahead_size); | ||||||
|             const mz_uint8 *pSrc_end = pSrc + num_bytes_to_process; |             const mz_uint8 *pSrc_end = pSrc ? pSrc + num_bytes_to_process : NULL; | ||||||
|             src_buf_left -= num_bytes_to_process; |             src_buf_left -= num_bytes_to_process; | ||||||
|             d->m_lookahead_size += num_bytes_to_process; |             d->m_lookahead_size += num_bytes_to_process; | ||||||
|             while (pSrc != pSrc_end) |             while (pSrc != pSrc_end) | ||||||
| @@ -1305,8 +1304,8 @@ tdefl_status tdefl_compress(tdefl_compressor *d, const void *pIn_buf, size_t *pI | |||||||
|         d->m_finished = (flush == TDEFL_FINISH); |         d->m_finished = (flush == TDEFL_FINISH); | ||||||
|         if (flush == TDEFL_FULL_FLUSH) |         if (flush == TDEFL_FULL_FLUSH) | ||||||
|         { |         { | ||||||
|             MZ_CLEAR_OBJ(d->m_hash); |             MZ_CLEAR_ARR(d->m_hash); | ||||||
|             MZ_CLEAR_OBJ(d->m_next); |             MZ_CLEAR_ARR(d->m_next); | ||||||
|             d->m_dict_size = 0; |             d->m_dict_size = 0; | ||||||
|         } |         } | ||||||
|     } |     } | ||||||
| @@ -1329,11 +1328,12 @@ tdefl_status tdefl_init(tdefl_compressor *d, tdefl_put_buf_func_ptr pPut_buf_fun | |||||||
|     d->m_greedy_parsing = (flags & TDEFL_GREEDY_PARSING_FLAG) != 0; |     d->m_greedy_parsing = (flags & TDEFL_GREEDY_PARSING_FLAG) != 0; | ||||||
|     d->m_max_probes[1] = 1 + (((flags & 0xFFF) >> 2) + 2) / 3; |     d->m_max_probes[1] = 1 + (((flags & 0xFFF) >> 2) + 2) / 3; | ||||||
|     if (!(flags & TDEFL_NONDETERMINISTIC_PARSING_FLAG)) |     if (!(flags & TDEFL_NONDETERMINISTIC_PARSING_FLAG)) | ||||||
|         MZ_CLEAR_OBJ(d->m_hash); |         MZ_CLEAR_ARR(d->m_hash); | ||||||
|     d->m_lookahead_pos = d->m_lookahead_size = d->m_dict_size = d->m_total_lz_bytes = d->m_lz_code_buf_dict_pos = d->m_bits_in = 0; |     d->m_lookahead_pos = d->m_lookahead_size = d->m_dict_size = d->m_total_lz_bytes = d->m_lz_code_buf_dict_pos = d->m_bits_in = 0; | ||||||
|     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_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_code_buf = d->m_lz_code_buf + 1; | ||||||
|     d->m_pLZ_flags = d->m_lz_code_buf; |     d->m_pLZ_flags = d->m_lz_code_buf; | ||||||
|  |     *d->m_pLZ_flags = 0; | ||||||
|     d->m_num_flags_left = 8; |     d->m_num_flags_left = 8; | ||||||
|     d->m_pOutput_buf = d->m_output_buf; |     d->m_pOutput_buf = d->m_output_buf; | ||||||
|     d->m_pOutput_buf_end = d->m_output_buf; |     d->m_pOutput_buf_end = d->m_output_buf; | ||||||
| @@ -1349,7 +1349,7 @@ tdefl_status tdefl_init(tdefl_compressor *d, tdefl_put_buf_func_ptr pPut_buf_fun | |||||||
|     d->m_src_buf_left = 0; |     d->m_src_buf_left = 0; | ||||||
|     d->m_out_buf_ofs = 0; |     d->m_out_buf_ofs = 0; | ||||||
|     if (!(flags & TDEFL_NONDETERMINISTIC_PARSING_FLAG)) |     if (!(flags & TDEFL_NONDETERMINISTIC_PARSING_FLAG)) | ||||||
|         MZ_CLEAR_OBJ(d->m_dict); |         MZ_CLEAR_ARR(d->m_dict); | ||||||
|     memset(&d->m_huff_count[0][0], 0, sizeof(d->m_huff_count[0][0]) * TDEFL_MAX_HUFF_SYMBOLS_0); |     memset(&d->m_huff_count[0][0], 0, sizeof(d->m_huff_count[0][0]) * TDEFL_MAX_HUFF_SYMBOLS_0); | ||||||
|     memset(&d->m_huff_count[1][0], 0, sizeof(d->m_huff_count[1][0]) * TDEFL_MAX_HUFF_SYMBOLS_1); |     memset(&d->m_huff_count[1][0], 0, sizeof(d->m_huff_count[1][0]) * TDEFL_MAX_HUFF_SYMBOLS_1); | ||||||
|     return TDEFL_STATUS_OKAY; |     return TDEFL_STATUS_OKAY; | ||||||
| @@ -1559,7 +1559,7 @@ void *tdefl_write_image_to_png_file_in_memory(const void *pImage, int w, int h, | |||||||
| /* Allocate the tdefl_compressor and tinfl_decompressor structures in C so that */ | /* 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 */ | /* non-C language bindings to tdefL_ and tinfl_ API don't need to worry about */ | ||||||
| /* structure size and allocation mechanism. */ | /* structure size and allocation mechanism. */ | ||||||
| tdefl_compressor *tdefl_compressor_alloc() | tdefl_compressor *tdefl_compressor_alloc(void) | ||||||
| { | { | ||||||
|     return (tdefl_compressor *)MZ_MALLOC(sizeof(tdefl_compressor)); |     return (tdefl_compressor *)MZ_MALLOC(sizeof(tdefl_compressor)); | ||||||
| } | } | ||||||
| @@ -1577,3 +1577,5 @@ void tdefl_compressor_free(tdefl_compressor *pComp) | |||||||
| #ifdef __cplusplus | #ifdef __cplusplus | ||||||
| } | } | ||||||
| #endif | #endif | ||||||
|  |  | ||||||
|  | #endif /*#ifndef MINIZ_NO_DEFLATE_APIS*/ | ||||||
|   | |||||||
							
								
								
									
										30
									
								
								miniz_tdef.h
									
									
									
									
									
								
							
							
						
						
									
										30
									
								
								miniz_tdef.h
									
									
									
									
									
								
							| @@ -1,6 +1,8 @@ | |||||||
| #pragma once | #pragma once | ||||||
| #include "miniz_common.h" | #include "miniz_common.h" | ||||||
|  |  | ||||||
|  | #ifndef MINIZ_NO_DEFLATE_APIS | ||||||
|  |  | ||||||
| #ifdef __cplusplus | #ifdef __cplusplus | ||||||
| extern "C" { | extern "C" { | ||||||
| #endif | #endif | ||||||
| @@ -48,11 +50,11 @@ enum | |||||||
| /*  Function returns a pointer to the compressed data, or NULL on failure. */ | /*  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. */ | /*  *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. */ | /*  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. */ | /* tdefl_compress_mem_to_mem() compresses a block in memory to another block in memory. */ | ||||||
| /* Returns 0 on failure. */ | /* 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. */ | /* Compresses an image to a compressed PNG file in memory. */ | ||||||
| /* On entry: */ | /* On entry: */ | ||||||
| @@ -64,14 +66,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. */ | /*  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. */ | /*  *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. */ | /*  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); | 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); | ||||||
| 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(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. */ | /* 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); | 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. */ | /* 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 | enum | ||||||
| { | { | ||||||
| @@ -159,32 +161,34 @@ 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. */ | /* 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. */ | /* 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.) */ | /* 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. */ | /* 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() 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_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); | MINIZ_EXPORT tdefl_status tdefl_get_prev_return_status(tdefl_compressor *d); | ||||||
| mz_uint32 tdefl_get_adler32(tdefl_compressor *d); | MINIZ_EXPORT mz_uint32 tdefl_get_adler32(tdefl_compressor *d); | ||||||
|  |  | ||||||
| /* Create tdefl_compress() flags given zlib-style compression parameters. */ | /* 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) */ | /* 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) */ | /* 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 */ | /* 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 | #ifndef MINIZ_NO_MALLOC | ||||||
| /* Allocate the tdefl_compressor structure in C so that */ | /* Allocate the tdefl_compressor structure in C so that */ | ||||||
| /* non-C language bindings to tdefl_ API don't need to worry about */ | /* non-C language bindings to tdefl_ API don't need to worry about */ | ||||||
| /* structure size and allocation mechanism. */ | /* structure size and allocation mechanism. */ | ||||||
| tdefl_compressor *tdefl_compressor_alloc(void); | MINIZ_EXPORT tdefl_compressor *tdefl_compressor_alloc(void); | ||||||
| void tdefl_compressor_free(tdefl_compressor *pComp); | MINIZ_EXPORT void tdefl_compressor_free(tdefl_compressor *pComp); | ||||||
| #endif | #endif | ||||||
|  |  | ||||||
| #ifdef __cplusplus | #ifdef __cplusplus | ||||||
| } | } | ||||||
| #endif | #endif | ||||||
|  |  | ||||||
|  | #endif /*#ifndef MINIZ_NO_DEFLATE_APIS*/ | ||||||
|   | |||||||
							
								
								
									
										119
									
								
								miniz_tinfl.c
									
									
									
									
									
								
							
							
						
						
									
										119
									
								
								miniz_tinfl.c
									
									
									
									
									
								
							| @@ -24,7 +24,9 @@ | |||||||
|  * |  * | ||||||
|  **************************************************************************/ |  **************************************************************************/ | ||||||
|  |  | ||||||
| #include "miniz_tinfl.h" | #include "miniz.h" | ||||||
|  |  | ||||||
|  | #ifndef MINIZ_NO_INFLATE_APIS | ||||||
|  |  | ||||||
| #ifdef __cplusplus | #ifdef __cplusplus | ||||||
| extern "C" { | extern "C" { | ||||||
| @@ -106,10 +108,10 @@ extern "C" { | |||||||
| /* It reads just enough bytes from the input stream that are needed to decode the next Huffman code (and absolutely no more). It works by trying to fully decode a */ | /* It reads just enough bytes from the input stream that are needed to decode the next Huffman code (and absolutely no more). It works by trying to fully decode a */ | ||||||
| /* Huffman code by using whatever bits are currently present in the bit buffer. If this fails, it reads another byte, and tries again until it succeeds or until the */ | /* Huffman code by using whatever bits are currently present in the bit buffer. If this fails, it reads another byte, and tries again until it succeeds or until the */ | ||||||
| /* bit buffer contains >=15 bits (deflate's max. Huffman code size). */ | /* bit buffer contains >=15 bits (deflate's max. Huffman code size). */ | ||||||
| #define TINFL_HUFF_BITBUF_FILL(state_index, pHuff)                             \ | #define TINFL_HUFF_BITBUF_FILL(state_index, pLookUp, pTree)                    \ | ||||||
|     do                                                                         \ |     do                                                                         \ | ||||||
|     {                                                                          \ |     {                                                                          \ | ||||||
|         temp = (pHuff)->m_look_up[bit_buf & (TINFL_FAST_LOOKUP_SIZE - 1)];     \ |         temp = pLookUp[bit_buf & (TINFL_FAST_LOOKUP_SIZE - 1)];                \ | ||||||
|         if (temp >= 0)                                                         \ |         if (temp >= 0)                                                         \ | ||||||
|         {                                                                      \ |         {                                                                      \ | ||||||
|             code_len = temp >> 9;                                              \ |             code_len = temp >> 9;                                              \ | ||||||
| @@ -121,7 +123,7 @@ extern "C" { | |||||||
|             code_len = TINFL_FAST_LOOKUP_BITS;                                 \ |             code_len = TINFL_FAST_LOOKUP_BITS;                                 \ | ||||||
|             do                                                                 \ |             do                                                                 \ | ||||||
|             {                                                                  \ |             {                                                                  \ | ||||||
|                 temp = (pHuff)->m_tree[~temp + ((bit_buf >> code_len++) & 1)]; \ |                 temp = pTree[~temp + ((bit_buf >> code_len++) & 1)];           \ | ||||||
|             } while ((temp < 0) && (num_bits >= (code_len + 1)));              \ |             } while ((temp < 0) && (num_bits >= (code_len + 1)));              \ | ||||||
|             if (temp >= 0)                                                     \ |             if (temp >= 0)                                                     \ | ||||||
|                 break;                                                         \ |                 break;                                                         \ | ||||||
| @@ -137,7 +139,7 @@ extern "C" { | |||||||
| /* The slow path is only executed at the very end of the input buffer. */ | /* The slow path is only executed at the very end of the input buffer. */ | ||||||
| /* v1.16: The original macro handled the case at the very end of the passed-in input buffer, but we also need to handle the case where the user passes in 1+zillion bytes */ | /* v1.16: The original macro handled the case at the very end of the passed-in input buffer, but we also need to handle the case where the user passes in 1+zillion bytes */ | ||||||
| /* following the deflate data and our non-conservative read-ahead path won't kick in here on this code. This is much trickier. */ | /* following the deflate data and our non-conservative read-ahead path won't kick in here on this code. This is much trickier. */ | ||||||
| #define TINFL_HUFF_DECODE(state_index, sym, pHuff)                                                                                  \ | #define TINFL_HUFF_DECODE(state_index, sym, pLookUp, pTree)                                                                         \ | ||||||
|     do                                                                                                                              \ |     do                                                                                                                              \ | ||||||
|     {                                                                                                                               \ |     {                                                                                                                               \ | ||||||
|         int temp;                                                                                                                   \ |         int temp;                                                                                                                   \ | ||||||
| @@ -146,7 +148,7 @@ extern "C" { | |||||||
|         {                                                                                                                           \ |         {                                                                                                                           \ | ||||||
|             if ((pIn_buf_end - pIn_buf_cur) < 2)                                                                                    \ |             if ((pIn_buf_end - pIn_buf_cur) < 2)                                                                                    \ | ||||||
|             {                                                                                                                       \ |             {                                                                                                                       \ | ||||||
|                 TINFL_HUFF_BITBUF_FILL(state_index, pHuff);                                                                         \ |                 TINFL_HUFF_BITBUF_FILL(state_index, pLookUp, pTree);                                                                \ | ||||||
|             }                                                                                                                       \ |             }                                                                                                                       \ | ||||||
|             else                                                                                                                    \ |             else                                                                                                                    \ | ||||||
|             {                                                                                                                       \ |             {                                                                                                                       \ | ||||||
| @@ -155,14 +157,14 @@ extern "C" { | |||||||
|                 num_bits += 16;                                                                                                     \ |                 num_bits += 16;                                                                                                     \ | ||||||
|             }                                                                                                                       \ |             }                                                                                                                       \ | ||||||
|         }                                                                                                                           \ |         }                                                                                                                           \ | ||||||
|         if ((temp = (pHuff)->m_look_up[bit_buf & (TINFL_FAST_LOOKUP_SIZE - 1)]) >= 0)                                               \ |         if ((temp = pLookUp[bit_buf & (TINFL_FAST_LOOKUP_SIZE - 1)]) >= 0)                                                          \ | ||||||
|             code_len = temp >> 9, temp &= 511;                                                                                      \ |             code_len = temp >> 9, temp &= 511;                                                                                      \ | ||||||
|         else                                                                                                                        \ |         else                                                                                                                        \ | ||||||
|         {                                                                                                                           \ |         {                                                                                                                           \ | ||||||
|             code_len = TINFL_FAST_LOOKUP_BITS;                                                                                      \ |             code_len = TINFL_FAST_LOOKUP_BITS;                                                                                      \ | ||||||
|             do                                                                                                                      \ |             do                                                                                                                      \ | ||||||
|             {                                                                                                                       \ |             {                                                                                                                       \ | ||||||
|                 temp = (pHuff)->m_tree[~temp + ((bit_buf >> code_len++) & 1)];                                                      \ |                 temp = pTree[~temp + ((bit_buf >> code_len++) & 1)];                                                                \ | ||||||
|             } while (temp < 0);                                                                                                     \ |             } while (temp < 0);                                                                                                     \ | ||||||
|         }                                                                                                                           \ |         }                                                                                                                           \ | ||||||
|         sym = temp;                                                                                                                 \ |         sym = temp;                                                                                                                 \ | ||||||
| @@ -171,20 +173,33 @@ extern "C" { | |||||||
|     }                                                                                                                               \ |     }                                                                                                                               \ | ||||||
|     MZ_MACRO_END |     MZ_MACRO_END | ||||||
|  |  | ||||||
|  | static void tinfl_clear_tree(tinfl_decompressor *r) | ||||||
|  | { | ||||||
|  |     if (r->m_type == 0) | ||||||
|  |         MZ_CLEAR_ARR(r->m_tree_0); | ||||||
|  |     else if (r->m_type == 1) | ||||||
|  |         MZ_CLEAR_ARR(r->m_tree_1); | ||||||
|  |     else | ||||||
|  |         MZ_CLEAR_ARR(r->m_tree_2); | ||||||
|  | } | ||||||
|  |  | ||||||
| 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) | 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) | ||||||
| { | { | ||||||
|     static const int s_length_base[31] = { 3, 4, 5, 6, 7, 8, 9, 10, 11, 13, 15, 17, 19, 23, 27, 31, 35, 43, 51, 59, 67, 83, 99, 115, 131, 163, 195, 227, 258, 0, 0 }; |     static const mz_uint16 s_length_base[31] = { 3, 4, 5, 6, 7, 8, 9, 10, 11, 13, 15, 17, 19, 23, 27, 31, 35, 43, 51, 59, 67, 83, 99, 115, 131, 163, 195, 227, 258, 0, 0 }; | ||||||
|     static const int s_length_extra[31] = { 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 2, 2, 2, 2, 3, 3, 3, 3, 4, 4, 4, 4, 5, 5, 5, 5, 0, 0, 0 }; |     static const mz_uint8 s_length_extra[31] = { 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 2, 2, 2, 2, 3, 3, 3, 3, 4, 4, 4, 4, 5, 5, 5, 5, 0, 0, 0 }; | ||||||
|     static const int s_dist_base[32] = { 1, 2, 3, 4, 5, 7, 9, 13, 17, 25, 33, 49, 65, 97, 129, 193, 257, 385, 513, 769, 1025, 1537, 2049, 3073, 4097, 6145, 8193, 12289, 16385, 24577, 0, 0 }; |     static const mz_uint16 s_dist_base[32] = { 1, 2, 3, 4, 5, 7, 9, 13, 17, 25, 33, 49, 65, 97, 129, 193, 257, 385, 513, 769, 1025, 1537, 2049, 3073, 4097, 6145, 8193, 12289, 16385, 24577, 0, 0 }; | ||||||
|     static const int s_dist_extra[32] = { 0, 0, 0, 0, 1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 6, 6, 7, 7, 8, 8, 9, 9, 10, 10, 11, 11, 12, 12, 13, 13 }; |     static const mz_uint8 s_dist_extra[32] = { 0, 0, 0, 0, 1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 6, 6, 7, 7, 8, 8, 9, 9, 10, 10, 11, 11, 12, 12, 13, 13 }; | ||||||
|     static const mz_uint8 s_length_dezigzag[19] = { 16, 17, 18, 0, 8, 7, 9, 6, 10, 5, 11, 4, 12, 3, 13, 2, 14, 1, 15 }; |     static const mz_uint8 s_length_dezigzag[19] = { 16, 17, 18, 0, 8, 7, 9, 6, 10, 5, 11, 4, 12, 3, 13, 2, 14, 1, 15 }; | ||||||
|     static const int s_min_table_sizes[3] = { 257, 1, 4 }; |     static const mz_uint16 s_min_table_sizes[3] = { 257, 1, 4 }; | ||||||
|  |  | ||||||
|  |     mz_int16 *pTrees[3]; | ||||||
|  |     mz_uint8 *pCode_sizes[3]; | ||||||
|  |  | ||||||
|     tinfl_status status = TINFL_STATUS_FAILED; |     tinfl_status status = TINFL_STATUS_FAILED; | ||||||
|     mz_uint32 num_bits, dist, counter, num_extra; |     mz_uint32 num_bits, dist, counter, num_extra; | ||||||
|     tinfl_bit_buf_t bit_buf; |     tinfl_bit_buf_t bit_buf; | ||||||
|     const mz_uint8 *pIn_buf_cur = pIn_buf_next, *const pIn_buf_end = pIn_buf_next + *pIn_buf_size; |     const mz_uint8 *pIn_buf_cur = pIn_buf_next, *const pIn_buf_end = pIn_buf_next + *pIn_buf_size; | ||||||
|     mz_uint8 *pOut_buf_cur = pOut_buf_next, *const pOut_buf_end = pOut_buf_next + *pOut_buf_size; |     mz_uint8 *pOut_buf_cur = pOut_buf_next, *const pOut_buf_end = pOut_buf_next ? pOut_buf_next + *pOut_buf_size : NULL; | ||||||
|     size_t out_buf_size_mask = (decomp_flags & TINFL_FLAG_USING_NON_WRAPPING_OUTPUT_BUF) ? (size_t)-1 : ((pOut_buf_next - pOut_buf_start) + *pOut_buf_size) - 1, dist_from_out_buf_start; |     size_t out_buf_size_mask = (decomp_flags & TINFL_FLAG_USING_NON_WRAPPING_OUTPUT_BUF) ? (size_t)-1 : ((pOut_buf_next - pOut_buf_start) + *pOut_buf_size) - 1, dist_from_out_buf_start; | ||||||
|  |  | ||||||
|     /* Ensure the output buffer's size is a power of 2, unless the output buffer is large enough to hold the entire output file (in which case it doesn't matter). */ |     /* Ensure the output buffer's size is a power of 2, unless the output buffer is large enough to hold the entire output file (in which case it doesn't matter). */ | ||||||
| @@ -194,6 +209,13 @@ tinfl_status tinfl_decompress(tinfl_decompressor *r, const mz_uint8 *pIn_buf_nex | |||||||
|         return TINFL_STATUS_BAD_PARAM; |         return TINFL_STATUS_BAD_PARAM; | ||||||
|     } |     } | ||||||
|  |  | ||||||
|  |     pTrees[0] = r->m_tree_0; | ||||||
|  |     pTrees[1] = r->m_tree_1; | ||||||
|  |     pTrees[2] = r->m_tree_2; | ||||||
|  |     pCode_sizes[0] = r->m_code_size_0; | ||||||
|  |     pCode_sizes[1] = r->m_code_size_1; | ||||||
|  |     pCode_sizes[2] = r->m_code_size_2; | ||||||
|  |  | ||||||
|     num_bits = r->m_num_bits; |     num_bits = r->m_num_bits; | ||||||
|     bit_buf = r->m_bit_buf; |     bit_buf = r->m_bit_buf; | ||||||
|     dist = r->m_dist; |     dist = r->m_dist; | ||||||
| @@ -271,11 +293,11 @@ tinfl_status tinfl_decompress(tinfl_decompressor *r, const mz_uint8 *pIn_buf_nex | |||||||
|         { |         { | ||||||
|             if (r->m_type == 1) |             if (r->m_type == 1) | ||||||
|             { |             { | ||||||
|                 mz_uint8 *p = r->m_tables[0].m_code_size; |                 mz_uint8 *p = r->m_code_size_0; | ||||||
|                 mz_uint i; |                 mz_uint i; | ||||||
|                 r->m_table_sizes[0] = 288; |                 r->m_table_sizes[0] = 288; | ||||||
|                 r->m_table_sizes[1] = 32; |                 r->m_table_sizes[1] = 32; | ||||||
|                 TINFL_MEMSET(r->m_tables[1].m_code_size, 5, 32); |                 TINFL_MEMSET(r->m_code_size_1, 5, 32); | ||||||
|                 for (i = 0; i <= 143; ++i) |                 for (i = 0; i <= 143; ++i) | ||||||
|                     *p++ = 8; |                     *p++ = 8; | ||||||
|                 for (; i <= 255; ++i) |                 for (; i <= 255; ++i) | ||||||
| @@ -292,26 +314,30 @@ tinfl_status tinfl_decompress(tinfl_decompressor *r, const mz_uint8 *pIn_buf_nex | |||||||
|                     TINFL_GET_BITS(11, r->m_table_sizes[counter], "\05\05\04"[counter]); |                     TINFL_GET_BITS(11, r->m_table_sizes[counter], "\05\05\04"[counter]); | ||||||
|                     r->m_table_sizes[counter] += s_min_table_sizes[counter]; |                     r->m_table_sizes[counter] += s_min_table_sizes[counter]; | ||||||
|                 } |                 } | ||||||
|                 MZ_CLEAR_OBJ(r->m_tables[2].m_code_size); |                 MZ_CLEAR_ARR(r->m_code_size_2); | ||||||
|                 for (counter = 0; counter < r->m_table_sizes[2]; counter++) |                 for (counter = 0; counter < r->m_table_sizes[2]; counter++) | ||||||
|                 { |                 { | ||||||
|                     mz_uint s; |                     mz_uint s; | ||||||
|                     TINFL_GET_BITS(14, s, 3); |                     TINFL_GET_BITS(14, s, 3); | ||||||
|                     r->m_tables[2].m_code_size[s_length_dezigzag[counter]] = (mz_uint8)s; |                     r->m_code_size_2[s_length_dezigzag[counter]] = (mz_uint8)s; | ||||||
|                 } |                 } | ||||||
|                 r->m_table_sizes[2] = 19; |                 r->m_table_sizes[2] = 19; | ||||||
|             } |             } | ||||||
|             for (; (int)r->m_type >= 0; r->m_type--) |             for (; (int)r->m_type >= 0; r->m_type--) | ||||||
|             { |             { | ||||||
|                 int tree_next, tree_cur; |                 int tree_next, tree_cur; | ||||||
|                 tinfl_huff_table *pTable; |                 mz_int16 *pLookUp; | ||||||
|  |                 mz_int16 *pTree; | ||||||
|  |                 mz_uint8 *pCode_size; | ||||||
|                 mz_uint i, j, used_syms, total, sym_index, next_code[17], total_syms[16]; |                 mz_uint i, j, used_syms, total, sym_index, next_code[17], total_syms[16]; | ||||||
|                 pTable = &r->m_tables[r->m_type]; |                 pLookUp = r->m_look_up[r->m_type]; | ||||||
|                 MZ_CLEAR_OBJ(total_syms); |                 pTree = pTrees[r->m_type]; | ||||||
|                 MZ_CLEAR_OBJ(pTable->m_look_up); |                 pCode_size = pCode_sizes[r->m_type]; | ||||||
|                 MZ_CLEAR_OBJ(pTable->m_tree); |                 MZ_CLEAR_ARR(total_syms); | ||||||
|  |                 TINFL_MEMSET(pLookUp, 0, sizeof(r->m_look_up[0])); | ||||||
|  |                 tinfl_clear_tree(r); | ||||||
|                 for (i = 0; i < r->m_table_sizes[r->m_type]; ++i) |                 for (i = 0; i < r->m_table_sizes[r->m_type]; ++i) | ||||||
|                     total_syms[pTable->m_code_size[i]]++; |                     total_syms[pCode_size[i]]++; | ||||||
|                 used_syms = 0, total = 0; |                 used_syms = 0, total = 0; | ||||||
|                 next_code[0] = next_code[1] = 0; |                 next_code[0] = next_code[1] = 0; | ||||||
|                 for (i = 1; i <= 15; ++i) |                 for (i = 1; i <= 15; ++i) | ||||||
| @@ -325,7 +351,7 @@ tinfl_status tinfl_decompress(tinfl_decompressor *r, const mz_uint8 *pIn_buf_nex | |||||||
|                 } |                 } | ||||||
|                 for (tree_next = -1, sym_index = 0; sym_index < r->m_table_sizes[r->m_type]; ++sym_index) |                 for (tree_next = -1, sym_index = 0; sym_index < r->m_table_sizes[r->m_type]; ++sym_index) | ||||||
|                 { |                 { | ||||||
|                     mz_uint rev_code = 0, l, cur_code, code_size = pTable->m_code_size[sym_index]; |                     mz_uint rev_code = 0, l, cur_code, code_size = pCode_size[sym_index]; | ||||||
|                     if (!code_size) |                     if (!code_size) | ||||||
|                         continue; |                         continue; | ||||||
|                     cur_code = next_code[code_size]++; |                     cur_code = next_code[code_size]++; | ||||||
| @@ -336,14 +362,14 @@ tinfl_status tinfl_decompress(tinfl_decompressor *r, const mz_uint8 *pIn_buf_nex | |||||||
|                         mz_int16 k = (mz_int16)((code_size << 9) | sym_index); |                         mz_int16 k = (mz_int16)((code_size << 9) | sym_index); | ||||||
|                         while (rev_code < TINFL_FAST_LOOKUP_SIZE) |                         while (rev_code < TINFL_FAST_LOOKUP_SIZE) | ||||||
|                         { |                         { | ||||||
|                             pTable->m_look_up[rev_code] = k; |                             pLookUp[rev_code] = k; | ||||||
|                             rev_code += (1 << code_size); |                             rev_code += (1 << code_size); | ||||||
|                         } |                         } | ||||||
|                         continue; |                         continue; | ||||||
|                     } |                     } | ||||||
|                     if (0 == (tree_cur = pTable->m_look_up[rev_code & (TINFL_FAST_LOOKUP_SIZE - 1)])) |                     if (0 == (tree_cur = pLookUp[rev_code & (TINFL_FAST_LOOKUP_SIZE - 1)])) | ||||||
|                     { |                     { | ||||||
|                         pTable->m_look_up[rev_code & (TINFL_FAST_LOOKUP_SIZE - 1)] = (mz_int16)tree_next; |                         pLookUp[rev_code & (TINFL_FAST_LOOKUP_SIZE - 1)] = (mz_int16)tree_next; | ||||||
|                         tree_cur = tree_next; |                         tree_cur = tree_next; | ||||||
|                         tree_next -= 2; |                         tree_next -= 2; | ||||||
|                     } |                     } | ||||||
| @@ -351,24 +377,24 @@ tinfl_status tinfl_decompress(tinfl_decompressor *r, const mz_uint8 *pIn_buf_nex | |||||||
|                     for (j = code_size; j > (TINFL_FAST_LOOKUP_BITS + 1); j--) |                     for (j = code_size; j > (TINFL_FAST_LOOKUP_BITS + 1); j--) | ||||||
|                     { |                     { | ||||||
|                         tree_cur -= ((rev_code >>= 1) & 1); |                         tree_cur -= ((rev_code >>= 1) & 1); | ||||||
|                         if (!pTable->m_tree[-tree_cur - 1]) |                         if (!pTree[-tree_cur - 1]) | ||||||
|                         { |                         { | ||||||
|                             pTable->m_tree[-tree_cur - 1] = (mz_int16)tree_next; |                             pTree[-tree_cur - 1] = (mz_int16)tree_next; | ||||||
|                             tree_cur = tree_next; |                             tree_cur = tree_next; | ||||||
|                             tree_next -= 2; |                             tree_next -= 2; | ||||||
|                         } |                         } | ||||||
|                         else |                         else | ||||||
|                             tree_cur = pTable->m_tree[-tree_cur - 1]; |                             tree_cur = pTree[-tree_cur - 1]; | ||||||
|                     } |                     } | ||||||
|                     tree_cur -= ((rev_code >>= 1) & 1); |                     tree_cur -= ((rev_code >>= 1) & 1); | ||||||
|                     pTable->m_tree[-tree_cur - 1] = (mz_int16)sym_index; |                     pTree[-tree_cur - 1] = (mz_int16)sym_index; | ||||||
|                 } |                 } | ||||||
|                 if (r->m_type == 2) |                 if (r->m_type == 2) | ||||||
|                 { |                 { | ||||||
|                     for (counter = 0; counter < (r->m_table_sizes[0] + r->m_table_sizes[1]);) |                     for (counter = 0; counter < (r->m_table_sizes[0] + r->m_table_sizes[1]);) | ||||||
|                     { |                     { | ||||||
|                         mz_uint s; |                         mz_uint s; | ||||||
|                         TINFL_HUFF_DECODE(16, dist, &r->m_tables[2]); |                         TINFL_HUFF_DECODE(16, dist, r->m_look_up[2], r->m_tree_2); | ||||||
|                         if (dist < 16) |                         if (dist < 16) | ||||||
|                         { |                         { | ||||||
|                             r->m_len_codes[counter++] = (mz_uint8)dist; |                             r->m_len_codes[counter++] = (mz_uint8)dist; | ||||||
| @@ -388,8 +414,8 @@ tinfl_status tinfl_decompress(tinfl_decompressor *r, const mz_uint8 *pIn_buf_nex | |||||||
|                     { |                     { | ||||||
|                         TINFL_CR_RETURN_FOREVER(21, TINFL_STATUS_FAILED); |                         TINFL_CR_RETURN_FOREVER(21, TINFL_STATUS_FAILED); | ||||||
|                     } |                     } | ||||||
|                     TINFL_MEMCPY(r->m_tables[0].m_code_size, r->m_len_codes, r->m_table_sizes[0]); |                     TINFL_MEMCPY(r->m_code_size_0, r->m_len_codes, r->m_table_sizes[0]); | ||||||
|                     TINFL_MEMCPY(r->m_tables[1].m_code_size, r->m_len_codes + r->m_table_sizes[0], r->m_table_sizes[1]); |                     TINFL_MEMCPY(r->m_code_size_1, r->m_len_codes + r->m_table_sizes[0], r->m_table_sizes[1]); | ||||||
|                 } |                 } | ||||||
|             } |             } | ||||||
|             for (;;) |             for (;;) | ||||||
| @@ -399,7 +425,7 @@ tinfl_status tinfl_decompress(tinfl_decompressor *r, const mz_uint8 *pIn_buf_nex | |||||||
|                 { |                 { | ||||||
|                     if (((pIn_buf_end - pIn_buf_cur) < 4) || ((pOut_buf_end - pOut_buf_cur) < 2)) |                     if (((pIn_buf_end - pIn_buf_cur) < 4) || ((pOut_buf_end - pOut_buf_cur) < 2)) | ||||||
|                     { |                     { | ||||||
|                         TINFL_HUFF_DECODE(23, counter, &r->m_tables[0]); |                         TINFL_HUFF_DECODE(23, counter, r->m_look_up[0], r->m_tree_0); | ||||||
|                         if (counter >= 256) |                         if (counter >= 256) | ||||||
|                             break; |                             break; | ||||||
|                         while (pOut_buf_cur >= pOut_buf_end) |                         while (pOut_buf_cur >= pOut_buf_end) | ||||||
| @@ -427,14 +453,14 @@ tinfl_status tinfl_decompress(tinfl_decompressor *r, const mz_uint8 *pIn_buf_nex | |||||||
|                             num_bits += 16; |                             num_bits += 16; | ||||||
|                         } |                         } | ||||||
| #endif | #endif | ||||||
|                         if ((sym2 = r->m_tables[0].m_look_up[bit_buf & (TINFL_FAST_LOOKUP_SIZE - 1)]) >= 0) |                         if ((sym2 = r->m_look_up[0][bit_buf & (TINFL_FAST_LOOKUP_SIZE - 1)]) >= 0) | ||||||
|                             code_len = sym2 >> 9; |                             code_len = sym2 >> 9; | ||||||
|                         else |                         else | ||||||
|                         { |                         { | ||||||
|                             code_len = TINFL_FAST_LOOKUP_BITS; |                             code_len = TINFL_FAST_LOOKUP_BITS; | ||||||
|                             do |                             do | ||||||
|                             { |                             { | ||||||
|                                 sym2 = r->m_tables[0].m_tree[~sym2 + ((bit_buf >> code_len++) & 1)]; |                                 sym2 = r->m_tree_0[~sym2 + ((bit_buf >> code_len++) & 1)]; | ||||||
|                             } while (sym2 < 0); |                             } while (sym2 < 0); | ||||||
|                         } |                         } | ||||||
|                         counter = sym2; |                         counter = sym2; | ||||||
| @@ -451,14 +477,14 @@ tinfl_status tinfl_decompress(tinfl_decompressor *r, const mz_uint8 *pIn_buf_nex | |||||||
|                             num_bits += 16; |                             num_bits += 16; | ||||||
|                         } |                         } | ||||||
| #endif | #endif | ||||||
|                         if ((sym2 = r->m_tables[0].m_look_up[bit_buf & (TINFL_FAST_LOOKUP_SIZE - 1)]) >= 0) |                         if ((sym2 = r->m_look_up[0][bit_buf & (TINFL_FAST_LOOKUP_SIZE - 1)]) >= 0) | ||||||
|                             code_len = sym2 >> 9; |                             code_len = sym2 >> 9; | ||||||
|                         else |                         else | ||||||
|                         { |                         { | ||||||
|                             code_len = TINFL_FAST_LOOKUP_BITS; |                             code_len = TINFL_FAST_LOOKUP_BITS; | ||||||
|                             do |                             do | ||||||
|                             { |                             { | ||||||
|                                 sym2 = r->m_tables[0].m_tree[~sym2 + ((bit_buf >> code_len++) & 1)]; |                                 sym2 = r->m_tree_0[~sym2 + ((bit_buf >> code_len++) & 1)]; | ||||||
|                             } while (sym2 < 0); |                             } while (sym2 < 0); | ||||||
|                         } |                         } | ||||||
|                         bit_buf >>= code_len; |                         bit_buf >>= code_len; | ||||||
| @@ -487,7 +513,7 @@ tinfl_status tinfl_decompress(tinfl_decompressor *r, const mz_uint8 *pIn_buf_nex | |||||||
|                     counter += extra_bits; |                     counter += extra_bits; | ||||||
|                 } |                 } | ||||||
|  |  | ||||||
|                 TINFL_HUFF_DECODE(26, dist, &r->m_tables[1]); |                 TINFL_HUFF_DECODE(26, dist, r->m_look_up[1], r->m_tree_1); | ||||||
|                 num_extra = s_dist_extra[dist]; |                 num_extra = s_dist_extra[dist]; | ||||||
|                 dist = s_dist_base[dist]; |                 dist = s_dist_base[dist]; | ||||||
|                 if (num_extra) |                 if (num_extra) | ||||||
| @@ -498,7 +524,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; |                 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); |                     TINFL_CR_RETURN_FOREVER(37, TINFL_STATUS_FAILED); | ||||||
|                 } |                 } | ||||||
| @@ -572,7 +598,7 @@ tinfl_status tinfl_decompress(tinfl_decompressor *r, const mz_uint8 *pIn_buf_nex | |||||||
|         --pIn_buf_cur; |         --pIn_buf_cur; | ||||||
|         num_bits -= 8; |         num_bits -= 8; | ||||||
|     } |     } | ||||||
|     bit_buf &= (tinfl_bit_buf_t)((((mz_uint64)1) << num_bits) - (mz_uint64)1); |     bit_buf &= ~(~(tinfl_bit_buf_t)0 << num_bits); | ||||||
|     MZ_ASSERT(!num_bits); /* if this assert fires then we've read beyond the end of non-deflate/zlib streams with following data (such as gzip streams). */ |     MZ_ASSERT(!num_bits); /* if this assert fires then we've read beyond the end of non-deflate/zlib streams with following data (such as gzip streams). */ | ||||||
|  |  | ||||||
|     if (decomp_flags & TINFL_FLAG_PARSE_ZLIB_HEADER) |     if (decomp_flags & TINFL_FLAG_PARSE_ZLIB_HEADER) | ||||||
| @@ -604,7 +630,7 @@ common_exit: | |||||||
|         } |         } | ||||||
|     } |     } | ||||||
|     r->m_num_bits = num_bits; |     r->m_num_bits = num_bits; | ||||||
|     r->m_bit_buf = bit_buf & (tinfl_bit_buf_t)((((mz_uint64)1) << num_bits) - (mz_uint64)1); |     r->m_bit_buf = bit_buf & ~(~(tinfl_bit_buf_t)0 << num_bits); | ||||||
|     r->m_dist = dist; |     r->m_dist = dist; | ||||||
|     r->m_counter = counter; |     r->m_counter = counter; | ||||||
|     r->m_num_extra = num_extra; |     r->m_num_extra = num_extra; | ||||||
| @@ -699,6 +725,7 @@ int tinfl_decompress_mem_to_callback(const void *pIn_buf, size_t *pIn_buf_size, | |||||||
|     size_t in_buf_ofs = 0, dict_ofs = 0; |     size_t in_buf_ofs = 0, dict_ofs = 0; | ||||||
|     if (!pDict) |     if (!pDict) | ||||||
|         return TINFL_STATUS_FAILED; |         return TINFL_STATUS_FAILED; | ||||||
|  |     memset(pDict,0,TINFL_LZ_DICT_SIZE); | ||||||
|     tinfl_init(&decomp); |     tinfl_init(&decomp); | ||||||
|     for (;;) |     for (;;) | ||||||
|     { |     { | ||||||
| @@ -721,7 +748,7 @@ int tinfl_decompress_mem_to_callback(const void *pIn_buf, size_t *pIn_buf_size, | |||||||
| } | } | ||||||
|  |  | ||||||
| #ifndef MINIZ_NO_MALLOC | #ifndef MINIZ_NO_MALLOC | ||||||
| tinfl_decompressor *tinfl_decompressor_alloc() | tinfl_decompressor *tinfl_decompressor_alloc(void) | ||||||
| { | { | ||||||
|     tinfl_decompressor *pDecomp = (tinfl_decompressor *)MZ_MALLOC(sizeof(tinfl_decompressor)); |     tinfl_decompressor *pDecomp = (tinfl_decompressor *)MZ_MALLOC(sizeof(tinfl_decompressor)); | ||||||
|     if (pDecomp) |     if (pDecomp) | ||||||
| @@ -738,3 +765,5 @@ void tinfl_decompressor_free(tinfl_decompressor *pDecomp) | |||||||
| #ifdef __cplusplus | #ifdef __cplusplus | ||||||
| } | } | ||||||
| #endif | #endif | ||||||
|  |  | ||||||
|  | #endif /*#ifndef MINIZ_NO_INFLATE_APIS*/ | ||||||
|   | |||||||
| @@ -2,6 +2,8 @@ | |||||||
| #include "miniz_common.h" | #include "miniz_common.h" | ||||||
| /* ------------------- Low-level Decompression API Definitions */ | /* ------------------- Low-level Decompression API Definitions */ | ||||||
|  |  | ||||||
|  | #ifndef MINIZ_NO_INFLATE_APIS | ||||||
|  |  | ||||||
| #ifdef __cplusplus | #ifdef __cplusplus | ||||||
| extern "C" { | extern "C" { | ||||||
| #endif | #endif | ||||||
| @@ -26,17 +28,17 @@ enum | |||||||
| /*  Function returns a pointer to the decompressed data, or NULL on failure. */ | /*  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. */ | /*  *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. */ | /*  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. */ | /* 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. */ | /* 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)) | #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. */ | /* 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. */ | /* Returns 1 on success or 0 on failure. */ | ||||||
| typedef int (*tinfl_put_buf_func_ptr)(const void *pBuf, int len, void *pUser); | 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; | struct tinfl_decompressor_tag; | ||||||
| typedef struct tinfl_decompressor_tag tinfl_decompressor; | typedef struct tinfl_decompressor_tag tinfl_decompressor; | ||||||
| @@ -45,8 +47,8 @@ typedef struct tinfl_decompressor_tag tinfl_decompressor; | |||||||
| /* Allocate the tinfl_decompressor structure in C so that */ | /* Allocate the tinfl_decompressor structure in C so that */ | ||||||
| /* non-C language bindings to tinfl_ API don't need to worry about */ | /* non-C language bindings to tinfl_ API don't need to worry about */ | ||||||
| /* structure size and allocation mechanism. */ | /* structure size and allocation mechanism. */ | ||||||
| tinfl_decompressor *tinfl_decompressor_alloc(void); | MINIZ_EXPORT tinfl_decompressor *tinfl_decompressor_alloc(void); | ||||||
| void tinfl_decompressor_free(tinfl_decompressor *pDecomp); | MINIZ_EXPORT void tinfl_decompressor_free(tinfl_decompressor *pDecomp); | ||||||
| #endif | #endif | ||||||
|  |  | ||||||
| /* Max size of LZ dictionary. */ | /* Max size of LZ dictionary. */ | ||||||
| @@ -97,7 +99,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. */ | /* 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. */ | /* 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. */ | /* Internal/private bits follow. */ | ||||||
| enum | enum | ||||||
| @@ -110,12 +112,6 @@ enum | |||||||
|     TINFL_FAST_LOOKUP_SIZE = 1 << TINFL_FAST_LOOKUP_BITS |     TINFL_FAST_LOOKUP_SIZE = 1 << TINFL_FAST_LOOKUP_BITS | ||||||
| }; | }; | ||||||
|  |  | ||||||
| typedef struct |  | ||||||
| { |  | ||||||
|     mz_uint8 m_code_size[TINFL_MAX_HUFF_SYMBOLS_0]; |  | ||||||
|     mz_int16 m_look_up[TINFL_FAST_LOOKUP_SIZE], m_tree[TINFL_MAX_HUFF_SYMBOLS_0 * 2]; |  | ||||||
| } tinfl_huff_table; |  | ||||||
|  |  | ||||||
| #if MINIZ_HAS_64BIT_REGISTERS | #if MINIZ_HAS_64BIT_REGISTERS | ||||||
| #define TINFL_USE_64BIT_BITBUF 1 | #define TINFL_USE_64BIT_BITBUF 1 | ||||||
| #else | #else | ||||||
| @@ -135,10 +131,18 @@ struct tinfl_decompressor_tag | |||||||
|     mz_uint32 m_state, m_num_bits, m_zhdr0, m_zhdr1, m_z_adler32, m_final, m_type, m_check_adler32, m_dist, m_counter, m_num_extra, m_table_sizes[TINFL_MAX_HUFF_TABLES]; |     mz_uint32 m_state, m_num_bits, m_zhdr0, m_zhdr1, m_z_adler32, m_final, m_type, m_check_adler32, m_dist, m_counter, m_num_extra, m_table_sizes[TINFL_MAX_HUFF_TABLES]; | ||||||
|     tinfl_bit_buf_t m_bit_buf; |     tinfl_bit_buf_t m_bit_buf; | ||||||
|     size_t m_dist_from_out_buf_start; |     size_t m_dist_from_out_buf_start; | ||||||
|     tinfl_huff_table m_tables[TINFL_MAX_HUFF_TABLES]; |     mz_int16 m_look_up[TINFL_MAX_HUFF_TABLES][TINFL_FAST_LOOKUP_SIZE]; | ||||||
|  |     mz_int16 m_tree_0[TINFL_MAX_HUFF_SYMBOLS_0 * 2]; | ||||||
|  |     mz_int16 m_tree_1[TINFL_MAX_HUFF_SYMBOLS_1 * 2]; | ||||||
|  |     mz_int16 m_tree_2[TINFL_MAX_HUFF_SYMBOLS_2 * 2]; | ||||||
|  |     mz_uint8 m_code_size_0[TINFL_MAX_HUFF_SYMBOLS_0]; | ||||||
|  |     mz_uint8 m_code_size_1[TINFL_MAX_HUFF_SYMBOLS_1]; | ||||||
|  |     mz_uint8 m_code_size_2[TINFL_MAX_HUFF_SYMBOLS_2]; | ||||||
|     mz_uint8 m_raw_header[4], m_len_codes[TINFL_MAX_HUFF_SYMBOLS_0 + TINFL_MAX_HUFF_SYMBOLS_1 + 137]; |     mz_uint8 m_raw_header[4], m_len_codes[TINFL_MAX_HUFF_SYMBOLS_0 + TINFL_MAX_HUFF_SYMBOLS_1 + 137]; | ||||||
| }; | }; | ||||||
|  |  | ||||||
| #ifdef __cplusplus | #ifdef __cplusplus | ||||||
| } | } | ||||||
| #endif | #endif | ||||||
|  |  | ||||||
|  | #endif /*#ifndef MINIZ_NO_INFLATE_APIS*/ | ||||||
|   | |||||||
							
								
								
									
										269
									
								
								miniz_zip.c
									
									
									
									
									
								
							
							
						
						
									
										269
									
								
								miniz_zip.c
									
									
									
									
									
								
							| @@ -24,7 +24,7 @@ | |||||||
|  * THE SOFTWARE. |  * THE SOFTWARE. | ||||||
|  * |  * | ||||||
|  **************************************************************************/ |  **************************************************************************/ | ||||||
| #include "miniz_zip.h" | #include "miniz.h" | ||||||
|  |  | ||||||
| #ifndef MINIZ_NO_ARCHIVE_APIS | #ifndef MINIZ_NO_ARCHIVE_APIS | ||||||
|  |  | ||||||
| @@ -40,19 +40,48 @@ extern "C" { | |||||||
| #include <sys/stat.h> | #include <sys/stat.h> | ||||||
|  |  | ||||||
| #if defined(_MSC_VER) || defined(__MINGW64__) | #if defined(_MSC_VER) || defined(__MINGW64__) | ||||||
|  |  | ||||||
|  | #define WIN32_LEAN_AND_MEAN | ||||||
|  | #include <windows.h> | ||||||
|  |  | ||||||
|  | static WCHAR* mz_utf8z_to_widechar(const char* str) | ||||||
|  | { | ||||||
|  |   int reqChars = MultiByteToWideChar(CP_UTF8, 0, str, -1, NULL, 0); | ||||||
|  |   WCHAR* wStr = (WCHAR*)malloc(reqChars * sizeof(WCHAR)); | ||||||
|  |   MultiByteToWideChar(CP_UTF8, 0, str, -1, wStr, sizeof(WCHAR) * reqChars); | ||||||
|  |   return wStr; | ||||||
|  | } | ||||||
|  |  | ||||||
| static FILE *mz_fopen(const char *pFilename, const char *pMode) | static FILE *mz_fopen(const char *pFilename, const char *pMode) | ||||||
| { | { | ||||||
|     FILE *pFile = NULL; |   WCHAR* wFilename = mz_utf8z_to_widechar(pFilename); | ||||||
|     fopen_s(&pFile, pFilename, pMode); |   WCHAR* wMode = mz_utf8z_to_widechar(pMode); | ||||||
|     return pFile; |   FILE* pFile = NULL; | ||||||
|  |   errno_t err = _wfopen_s(&pFile, wFilename, wMode); | ||||||
|  |   free(wFilename); | ||||||
|  |   free(wMode); | ||||||
|  |   return err ? NULL : pFile; | ||||||
| } | } | ||||||
|  |  | ||||||
| static FILE *mz_freopen(const char *pPath, const char *pMode, FILE *pStream) | static FILE *mz_freopen(const char *pPath, const char *pMode, FILE *pStream) | ||||||
| { | { | ||||||
|     FILE *pFile = NULL; |   WCHAR* wPath = mz_utf8z_to_widechar(pPath); | ||||||
|     if (freopen_s(&pFile, pPath, pMode, pStream)) |   WCHAR* wMode = mz_utf8z_to_widechar(pMode); | ||||||
|         return NULL; |   FILE* pFile = NULL; | ||||||
|     return pFile; |   errno_t err = _wfreopen_s(&pFile, wPath, wMode, pStream); | ||||||
|  |   free(wPath); | ||||||
|  |   free(wMode); | ||||||
|  |   return err ? NULL : pFile; | ||||||
| } | } | ||||||
|  |  | ||||||
|  | static int mz_stat64(const char *path, struct __stat64 *buffer) | ||||||
|  | { | ||||||
|  |   WCHAR* wPath = mz_utf8z_to_widechar(path); | ||||||
|  |   int res = _wstat64(wPath, buffer); | ||||||
|  |   free(wPath); | ||||||
|  |   return res; | ||||||
|  | } | ||||||
|  |  | ||||||
| #ifndef MINIZ_NO_TIME | #ifndef MINIZ_NO_TIME | ||||||
| #include <sys/utime.h> | #include <sys/utime.h> | ||||||
| #endif | #endif | ||||||
| @@ -63,11 +92,11 @@ static FILE *mz_freopen(const char *pPath, const char *pMode, FILE *pStream) | |||||||
| #define MZ_FTELL64 _ftelli64 | #define MZ_FTELL64 _ftelli64 | ||||||
| #define MZ_FSEEK64 _fseeki64 | #define MZ_FSEEK64 _fseeki64 | ||||||
| #define MZ_FILE_STAT_STRUCT _stat64 | #define MZ_FILE_STAT_STRUCT _stat64 | ||||||
| #define MZ_FILE_STAT _stat64 | #define MZ_FILE_STAT mz_stat64  | ||||||
| #define MZ_FFLUSH fflush | #define MZ_FFLUSH fflush | ||||||
| #define MZ_FREOPEN mz_freopen | #define MZ_FREOPEN mz_freopen | ||||||
| #define MZ_DELETE_FILE remove | #define MZ_DELETE_FILE remove | ||||||
| #elif defined(__MINGW32__) | #elif defined(__MINGW32__) || defined(__WATCOMC__) | ||||||
| #ifndef MINIZ_NO_TIME | #ifndef MINIZ_NO_TIME | ||||||
| #include <sys/utime.h> | #include <sys/utime.h> | ||||||
| #endif | #endif | ||||||
| @@ -75,10 +104,10 @@ static FILE *mz_freopen(const char *pPath, const char *pMode, FILE *pStream) | |||||||
| #define MZ_FCLOSE fclose | #define MZ_FCLOSE fclose | ||||||
| #define MZ_FREAD fread | #define MZ_FREAD fread | ||||||
| #define MZ_FWRITE fwrite | #define MZ_FWRITE fwrite | ||||||
| #define MZ_FTELL64 ftello64 | #define MZ_FTELL64 _ftelli64 | ||||||
| #define MZ_FSEEK64 fseeko64 | #define MZ_FSEEK64 _fseeki64 | ||||||
| #define MZ_FILE_STAT_STRUCT _stat | #define MZ_FILE_STAT_STRUCT stat | ||||||
| #define MZ_FILE_STAT _stat | #define MZ_FILE_STAT stat | ||||||
| #define MZ_FFLUSH fflush | #define MZ_FFLUSH fflush | ||||||
| #define MZ_FREOPEN(f, m, s) freopen(f, m, s) | #define MZ_FREOPEN(f, m, s) freopen(f, m, s) | ||||||
| #define MZ_DELETE_FILE remove | #define MZ_DELETE_FILE remove | ||||||
| @@ -97,7 +126,7 @@ static FILE *mz_freopen(const char *pPath, const char *pMode, FILE *pStream) | |||||||
| #define MZ_FFLUSH fflush | #define MZ_FFLUSH fflush | ||||||
| #define MZ_FREOPEN(f, m, s) freopen(f, m, s) | #define MZ_FREOPEN(f, m, s) freopen(f, m, s) | ||||||
| #define MZ_DELETE_FILE remove | #define MZ_DELETE_FILE remove | ||||||
| #elif defined(__GNUC__) && defined(_LARGEFILE64_SOURCE) | #elif defined(__USE_LARGEFILE64) /* gcc, clang */ | ||||||
| #ifndef MINIZ_NO_TIME | #ifndef MINIZ_NO_TIME | ||||||
| #include <utime.h> | #include <utime.h> | ||||||
| #endif | #endif | ||||||
| @@ -258,7 +287,7 @@ struct mz_zip_internal_state_tag | |||||||
|     mz_zip_array m_sorted_central_dir_offsets; |     mz_zip_array m_sorted_central_dir_offsets; | ||||||
|  |  | ||||||
|     /* The flags passed in when the archive is initially opened. */ |     /* The flags passed in when the archive is initially opened. */ | ||||||
|     uint32_t m_init_flags; |     mz_uint32 m_init_flags; | ||||||
|  |  | ||||||
|     /* MZ_TRUE if the archive has a zip64 end of central directory headers, etc. */ |     /* MZ_TRUE if the archive has a zip64 end of central directory headers, etc. */ | ||||||
|     mz_bool m_zip64; |     mz_bool m_zip64; | ||||||
| @@ -277,7 +306,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 | #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) | static MZ_FORCEINLINE mz_uint mz_zip_array_range_check(const mz_zip_array *pArray, mz_uint index) | ||||||
| { | { | ||||||
|     MZ_ASSERT(index < pArray->m_size); |     MZ_ASSERT(index < pArray->m_size); | ||||||
| @@ -845,7 +874,7 @@ static mz_bool mz_zip_reader_read_central_dir(mz_zip_archive *pZip, mz_uint flag | |||||||
| void mz_zip_zero_struct(mz_zip_archive *pZip) | void mz_zip_zero_struct(mz_zip_archive *pZip) | ||||||
| { | { | ||||||
|     if (pZip) |     if (pZip) | ||||||
|         MZ_CLEAR_OBJ(*pZip); |         MZ_CLEAR_PTR(pZip); | ||||||
| } | } | ||||||
|  |  | ||||||
| static mz_bool mz_zip_reader_end_internal(mz_zip_archive *pZip, mz_bool set_last_error) | static mz_bool mz_zip_reader_end_internal(mz_zip_archive *pZip, mz_bool set_last_error) | ||||||
| @@ -1319,7 +1348,7 @@ static mz_bool mz_zip_locate_file_binary_search(mz_zip_archive *pZip, const char | |||||||
|     const mz_zip_array *pCentral_dir_offsets = &pState->m_central_dir_offsets; |     const mz_zip_array *pCentral_dir_offsets = &pState->m_central_dir_offsets; | ||||||
|     const mz_zip_array *pCentral_dir = &pState->m_central_dir; |     const mz_zip_array *pCentral_dir = &pState->m_central_dir; | ||||||
|     mz_uint32 *pIndices = &MZ_ZIP_ARRAY_ELEMENT(&pState->m_sorted_central_dir_offsets, mz_uint32, 0); |     mz_uint32 *pIndices = &MZ_ZIP_ARRAY_ELEMENT(&pState->m_sorted_central_dir_offsets, mz_uint32, 0); | ||||||
|     const uint32_t size = pZip->m_total_files; |     const mz_uint32 size = pZip->m_total_files; | ||||||
|     const mz_uint filename_len = (mz_uint)strlen(pFilename); |     const mz_uint filename_len = (mz_uint)strlen(pFilename); | ||||||
|  |  | ||||||
|     if (pIndex) |     if (pIndex) | ||||||
| @@ -1334,7 +1363,7 @@ static mz_bool mz_zip_locate_file_binary_search(mz_zip_archive *pZip, const char | |||||||
|         while (l <= h) |         while (l <= h) | ||||||
|         { |         { | ||||||
|             mz_int64 m = l + ((h - l) >> 1); |             mz_int64 m = l + ((h - l) >> 1); | ||||||
|             uint32_t file_index = pIndices[(uint32_t)m]; |             mz_uint32 file_index = pIndices[(mz_uint32)m]; | ||||||
|  |  | ||||||
|             int comp = mz_zip_filename_compare(pCentral_dir, pCentral_dir_offsets, file_index, pFilename, filename_len); |             int comp = mz_zip_filename_compare(pCentral_dir, pCentral_dir_offsets, file_index, pFilename, filename_len); | ||||||
|             if (!comp) |             if (!comp) | ||||||
| @@ -1427,7 +1456,8 @@ mz_bool mz_zip_reader_locate_file_v2(mz_zip_archive *pZip, const char *pName, co | |||||||
|     return mz_zip_set_error(pZip, MZ_ZIP_FILE_NOT_FOUND); |     return mz_zip_set_error(pZip, MZ_ZIP_FILE_NOT_FOUND); | ||||||
| } | } | ||||||
|  |  | ||||||
| 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) | static | ||||||
|  | mz_bool mz_zip_reader_extract_to_mem_no_alloc1(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, const mz_zip_archive_file_stat *st) | ||||||
| { | { | ||||||
|     int status = TINFL_STATUS_DONE; |     int status = TINFL_STATUS_DONE; | ||||||
|     mz_uint64 needed_size, cur_file_ofs, comp_remaining, out_buf_ofs = 0, read_buf_size, read_buf_ofs = 0, read_buf_avail; |     mz_uint64 needed_size, cur_file_ofs, comp_remaining, out_buf_ofs = 0, read_buf_size, read_buf_ofs = 0, read_buf_avail; | ||||||
| @@ -1440,6 +1470,9 @@ mz_bool mz_zip_reader_extract_to_mem_no_alloc(mz_zip_archive *pZip, mz_uint file | |||||||
|     if ((!pZip) || (!pZip->m_pState) || ((buf_size) && (!pBuf)) || ((user_read_buf_size) && (!pUser_read_buf)) || (!pZip->m_pRead)) |     if ((!pZip) || (!pZip->m_pState) || ((buf_size) && (!pBuf)) || ((user_read_buf_size) && (!pUser_read_buf)) || (!pZip->m_pRead)) | ||||||
|         return mz_zip_set_error(pZip, MZ_ZIP_INVALID_PARAMETER); |         return mz_zip_set_error(pZip, MZ_ZIP_INVALID_PARAMETER); | ||||||
|  |  | ||||||
|  |     if (st) { | ||||||
|  |         file_stat = *st; | ||||||
|  |     } else | ||||||
|     if (!mz_zip_reader_file_stat(pZip, file_index, &file_stat)) |     if (!mz_zip_reader_file_stat(pZip, file_index, &file_stat)) | ||||||
|         return MZ_FALSE; |         return MZ_FALSE; | ||||||
|  |  | ||||||
| @@ -1570,17 +1603,22 @@ mz_bool mz_zip_reader_extract_to_mem_no_alloc(mz_zip_archive *pZip, mz_uint file | |||||||
|     return status == TINFL_STATUS_DONE; |     return status == TINFL_STATUS_DONE; | ||||||
| } | } | ||||||
|  |  | ||||||
|  | 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) | ||||||
|  | { | ||||||
|  |     return mz_zip_reader_extract_to_mem_no_alloc1(pZip, file_index, pBuf, buf_size, flags, pUser_read_buf, user_read_buf_size, NULL); | ||||||
|  | } | ||||||
|  |  | ||||||
| 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) | 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) | ||||||
| { | { | ||||||
|     mz_uint32 file_index; |     mz_uint32 file_index; | ||||||
|     if (!mz_zip_reader_locate_file_v2(pZip, pFilename, NULL, flags, &file_index)) |     if (!mz_zip_reader_locate_file_v2(pZip, pFilename, NULL, flags, &file_index)) | ||||||
|         return MZ_FALSE; |         return MZ_FALSE; | ||||||
|     return mz_zip_reader_extract_to_mem_no_alloc(pZip, file_index, pBuf, buf_size, flags, pUser_read_buf, user_read_buf_size); |     return mz_zip_reader_extract_to_mem_no_alloc1(pZip, file_index, pBuf, buf_size, flags, pUser_read_buf, user_read_buf_size, NULL); | ||||||
| } | } | ||||||
|  |  | ||||||
| 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_to_mem(mz_zip_archive *pZip, mz_uint file_index, void *pBuf, size_t buf_size, mz_uint flags) | ||||||
| { | { | ||||||
|     return mz_zip_reader_extract_to_mem_no_alloc(pZip, file_index, pBuf, buf_size, flags, NULL, 0); |     return mz_zip_reader_extract_to_mem_no_alloc1(pZip, file_index, pBuf, buf_size, flags, NULL, 0, NULL); | ||||||
| } | } | ||||||
|  |  | ||||||
| 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) | 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) | ||||||
| @@ -1590,23 +1628,17 @@ mz_bool mz_zip_reader_extract_file_to_mem(mz_zip_archive *pZip, const char *pFil | |||||||
|  |  | ||||||
| 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_to_heap(mz_zip_archive *pZip, mz_uint file_index, size_t *pSize, mz_uint flags) | ||||||
| { | { | ||||||
|     mz_uint64 comp_size, uncomp_size, alloc_size; |     mz_zip_archive_file_stat file_stat; | ||||||
|     const mz_uint8 *p = mz_zip_get_cdh(pZip, file_index); |     mz_uint64 alloc_size; | ||||||
|     void *pBuf; |     void *pBuf; | ||||||
|  |  | ||||||
|     if (pSize) |     if (pSize) | ||||||
|         *pSize = 0; |         *pSize = 0; | ||||||
|  |  | ||||||
|     if (!p) |     if (!mz_zip_reader_file_stat(pZip, file_index, &file_stat)) | ||||||
|     { |  | ||||||
|         mz_zip_set_error(pZip, MZ_ZIP_INVALID_PARAMETER); |  | ||||||
|         return NULL; |         return NULL; | ||||||
|     } |  | ||||||
|  |  | ||||||
|     comp_size = MZ_READ_LE32(p + MZ_ZIP_CDH_COMPRESSED_SIZE_OFS); |     alloc_size = (flags & MZ_ZIP_FLAG_COMPRESSED_DATA) ? file_stat.m_comp_size : file_stat.m_uncomp_size; | ||||||
|     uncomp_size = MZ_READ_LE32(p + MZ_ZIP_CDH_DECOMPRESSED_SIZE_OFS); |  | ||||||
|  |  | ||||||
|     alloc_size = (flags & MZ_ZIP_FLAG_COMPRESSED_DATA) ? comp_size : uncomp_size; |  | ||||||
|     if (((sizeof(size_t) == sizeof(mz_uint32))) && (alloc_size > 0x7FFFFFFF)) |     if (((sizeof(size_t) == sizeof(mz_uint32))) && (alloc_size > 0x7FFFFFFF)) | ||||||
|     { |     { | ||||||
|         mz_zip_set_error(pZip, MZ_ZIP_INTERNAL_ERROR); |         mz_zip_set_error(pZip, MZ_ZIP_INTERNAL_ERROR); | ||||||
| @@ -1619,7 +1651,7 @@ void *mz_zip_reader_extract_to_heap(mz_zip_archive *pZip, mz_uint file_index, si | |||||||
|         return NULL; |         return NULL; | ||||||
|     } |     } | ||||||
|  |  | ||||||
|     if (!mz_zip_reader_extract_to_mem(pZip, file_index, pBuf, (size_t)alloc_size, flags)) |     if (!mz_zip_reader_extract_to_mem_no_alloc1(pZip, file_index, pBuf, (size_t)alloc_size, flags, NULL, 0, &file_stat)) | ||||||
|     { |     { | ||||||
|         pZip->m_pFree(pZip->m_pAlloc_opaque, pBuf); |         pZip->m_pFree(pZip->m_pAlloc_opaque, pBuf); | ||||||
|         return NULL; |         return NULL; | ||||||
| @@ -1645,7 +1677,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) | 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; |     int status = TINFL_STATUS_DONE; | ||||||
|  | #ifndef MINIZ_DISABLE_ZIP_READER_CRC32_CHECKS | ||||||
|     mz_uint file_crc32 = MZ_CRC32_INIT; |     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_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; |     mz_zip_archive_file_stat file_stat; | ||||||
|     void *pRead_buf = NULL; |     void *pRead_buf = NULL; | ||||||
| @@ -1941,7 +1975,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))) |         if (!((flags & MZ_ZIP_FLAG_COMPRESSED_DATA) || (!pState->file_stat.m_method))) | ||||||
|         { |         { | ||||||
|             /* Decompression required, therefore intermediate read buffer required */ |             /* 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))) |             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); |                 mz_zip_set_error(pZip, MZ_ZIP_ALLOC_FAILED); | ||||||
| @@ -2078,7 +2112,7 @@ size_t mz_zip_reader_extract_iter_read(mz_zip_reader_extract_iter_state* pState, | |||||||
|                 size_t to_copy = MZ_MIN( (buf_size - copied_to_caller), pState->out_blk_remain ); |                 size_t to_copy = MZ_MIN( (buf_size - copied_to_caller), pState->out_blk_remain ); | ||||||
|  |  | ||||||
|                 /* Copy data to caller's buffer */ |                 /* Copy data to caller's buffer */ | ||||||
|                 memcpy( (uint8_t*)pvBuf + copied_to_caller, pWrite_buf_cur, to_copy ); |                 memcpy( (mz_uint8*)pvBuf + copied_to_caller, pWrite_buf_cur, to_copy ); | ||||||
|  |  | ||||||
| #ifndef MINIZ_DISABLE_ZIP_READER_CRC32_CHECKS | #ifndef MINIZ_DISABLE_ZIP_READER_CRC32_CHECKS | ||||||
|                 /* Perform CRC */ |                 /* Perform CRC */ | ||||||
| @@ -2299,7 +2333,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); |         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)) |     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) |     if (local_header_filename_len) | ||||||
|     { |     { | ||||||
| @@ -2333,14 +2370,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; |             mz_uint32 field_id, field_data_size, field_total_size; | ||||||
|  |  | ||||||
|             if (extra_size_remaining < (sizeof(mz_uint16) * 2)) |             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_id = MZ_READ_LE16(pExtra_data); | ||||||
|             field_data_size = MZ_READ_LE16(pExtra_data + sizeof(mz_uint16)); |             field_data_size = MZ_READ_LE16(pExtra_data + sizeof(mz_uint16)); | ||||||
|             field_total_size = field_data_size + sizeof(mz_uint16) * 2; |             field_total_size = field_data_size + sizeof(mz_uint16) * 2; | ||||||
|  |  | ||||||
|             if (field_total_size > extra_size_remaining) |             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) |             if (field_id == MZ_ZIP64_EXTENDED_INFORMATION_FIELD_HEADER_ID) | ||||||
|             { |             { | ||||||
| @@ -2438,7 +2481,7 @@ handle_failure: | |||||||
| mz_bool mz_zip_validate_archive(mz_zip_archive *pZip, mz_uint flags) | mz_bool mz_zip_validate_archive(mz_zip_archive *pZip, mz_uint flags) | ||||||
| { | { | ||||||
|     mz_zip_internal_state *pState; |     mz_zip_internal_state *pState; | ||||||
|     uint32_t i; |     mz_uint32 i; | ||||||
|  |  | ||||||
|     if ((!pZip) || (!pZip->m_pState) || (!pZip->m_pAlloc) || (!pZip->m_pFree) || (!pZip->m_pRead)) |     if ((!pZip) || (!pZip->m_pState) || (!pZip->m_pAlloc) || (!pZip->m_pFree) || (!pZip->m_pRead)) | ||||||
|         return mz_zip_set_error(pZip, MZ_ZIP_INVALID_PARAMETER); |         return mz_zip_set_error(pZip, MZ_ZIP_INVALID_PARAMETER); | ||||||
| @@ -2456,9 +2499,6 @@ mz_bool mz_zip_validate_archive(mz_zip_archive *pZip, mz_uint flags) | |||||||
|     } |     } | ||||||
|     else |     else | ||||||
|     { |     { | ||||||
|         if (pZip->m_total_files >= MZ_UINT32_MAX) |  | ||||||
|             return mz_zip_set_error(pZip, MZ_ZIP_ARCHIVE_TOO_LARGE); |  | ||||||
|  |  | ||||||
|         if (pState->m_central_dir.m_size >= MZ_UINT32_MAX) |         if (pState->m_central_dir.m_size >= MZ_UINT32_MAX) | ||||||
|             return mz_zip_set_error(pZip, MZ_ZIP_ARCHIVE_TOO_LARGE); |             return mz_zip_set_error(pZip, MZ_ZIP_ARCHIVE_TOO_LARGE); | ||||||
|     } |     } | ||||||
| @@ -2820,7 +2860,7 @@ mz_bool mz_zip_writer_init_file_v2(mz_zip_archive *pZip, const char *pFilename, | |||||||
|         mz_uint64 cur_ofs = 0; |         mz_uint64 cur_ofs = 0; | ||||||
|         char buf[4096]; |         char buf[4096]; | ||||||
|  |  | ||||||
|         MZ_CLEAR_OBJ(buf); |         MZ_CLEAR_ARR(buf); | ||||||
|  |  | ||||||
|         do |         do | ||||||
|         { |         { | ||||||
| @@ -3183,7 +3223,7 @@ mz_bool mz_zip_writer_add_mem_ex_v2(mz_zip_archive *pZip, const char *pArchive_n | |||||||
|             pState->m_zip64 = MZ_TRUE; |             pState->m_zip64 = MZ_TRUE; | ||||||
|             /*return mz_zip_set_error(pZip, MZ_ZIP_TOO_MANY_FILES); */ |             /*return mz_zip_set_error(pZip, MZ_ZIP_TOO_MANY_FILES); */ | ||||||
|         } |         } | ||||||
|         if ((buf_size > 0xFFFFFFFF) || (uncomp_size > 0xFFFFFFFF)) |         if (((mz_uint64)buf_size > 0xFFFFFFFF) || (uncomp_size > 0xFFFFFFFF)) | ||||||
|         { |         { | ||||||
|             pState->m_zip64 = MZ_TRUE; |             pState->m_zip64 = MZ_TRUE; | ||||||
|             /*return mz_zip_set_error(pZip, MZ_ZIP_ARCHIVE_TOO_LARGE); */ |             /*return mz_zip_set_error(pZip, MZ_ZIP_ARCHIVE_TOO_LARGE); */ | ||||||
| @@ -3233,8 +3273,8 @@ mz_bool mz_zip_writer_add_mem_ex_v2(mz_zip_archive *pZip, const char *pArchive_n | |||||||
|     if (!pState->m_zip64) |     if (!pState->m_zip64) | ||||||
|     { |     { | ||||||
|         /* Bail early if the archive would obviously become too large */ |         /* 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  |         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 +  | 			+ 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 | 			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) | 			+ MZ_ZIP_DATA_DESCRIPTER_SIZE32) > 0xFFFFFFFF) | ||||||
|         { |         { | ||||||
| @@ -3276,7 +3316,7 @@ mz_bool mz_zip_writer_add_mem_ex_v2(mz_zip_archive *pZip, const char *pArchive_n | |||||||
|     } |     } | ||||||
|     cur_archive_file_ofs += num_alignment_padding_bytes; |     cur_archive_file_ofs += num_alignment_padding_bytes; | ||||||
|  |  | ||||||
|     MZ_CLEAR_OBJ(local_dir_header); |     MZ_CLEAR_ARR(local_dir_header); | ||||||
|  |  | ||||||
|     if (!store_data_uncompressed || (level_and_flags & MZ_ZIP_FLAG_COMPRESSED_DATA)) |     if (!store_data_uncompressed || (level_and_flags & MZ_ZIP_FLAG_COMPRESSED_DATA)) | ||||||
|     { |     { | ||||||
| @@ -3423,35 +3463,37 @@ mz_bool mz_zip_writer_add_mem_ex_v2(mz_zip_archive *pZip, const char *pArchive_n | |||||||
|     return MZ_TRUE; |     return MZ_TRUE; | ||||||
| } | } | ||||||
|  |  | ||||||
| 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 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) |                                 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; | ||||||
|     mz_uint uncomp_crc32 = MZ_CRC32_INIT, level, num_alignment_padding_bytes; |     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_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; |     size_t archive_name_size; | ||||||
|     mz_uint8 local_dir_header[MZ_ZIP_LOCAL_DIR_HEADER_SIZE]; |     mz_uint8 local_dir_header[MZ_ZIP_LOCAL_DIR_HEADER_SIZE]; | ||||||
|     mz_uint8 *pExtra_data = NULL; |     mz_uint8 *pExtra_data = NULL; | ||||||
|     mz_uint32 extra_size = 0; |     mz_uint32 extra_size = 0; | ||||||
|     mz_uint8 extra_data[MZ_ZIP64_MAX_CENTRAL_EXTRA_FIELD_SIZE]; |     mz_uint8 extra_data[MZ_ZIP64_MAX_CENTRAL_EXTRA_FIELD_SIZE]; | ||||||
|     mz_zip_internal_state *pState; |     mz_zip_internal_state *pState; | ||||||
| 	mz_uint64 file_ofs = 0; |     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; |  | ||||||
|  |  | ||||||
|     if ((int)level_and_flags < 0) |     if ((int)level_and_flags < 0) | ||||||
|         level_and_flags = MZ_DEFAULT_LEVEL; |         level_and_flags = MZ_DEFAULT_LEVEL; | ||||||
|     level = level_and_flags & 0xF; |     level = level_and_flags & 0xF; | ||||||
|  |  | ||||||
|  |     gen_flags = (level_and_flags & MZ_ZIP_FLAG_WRITE_HEADER_SET_SIZE) ? 0 : MZ_ZIP_LDH_BIT_FLAG_HAS_LOCATOR; | ||||||
|  |  | ||||||
|  |     if (!(level_and_flags & MZ_ZIP_FLAG_ASCII_FILENAME)) | ||||||
|  |         gen_flags |= MZ_ZIP_GENERAL_PURPOSE_BIT_FLAG_UTF8; | ||||||
|  |  | ||||||
|     /* Sanity checks */ |     /* Sanity checks */ | ||||||
|     if ((!pZip) || (!pZip->m_pState) || (pZip->m_zip_mode != MZ_ZIP_MODE_WRITING) || (!pArchive_name) || ((comment_size) && (!pComment)) || (level > MZ_UBER_COMPRESSION)) |     if ((!pZip) || (!pZip->m_pState) || (pZip->m_zip_mode != MZ_ZIP_MODE_WRITING) || (!pArchive_name) || ((comment_size) && (!pComment)) || (level > MZ_UBER_COMPRESSION)) | ||||||
|         return mz_zip_set_error(pZip, MZ_ZIP_INVALID_PARAMETER); |         return mz_zip_set_error(pZip, MZ_ZIP_INVALID_PARAMETER); | ||||||
|  |  | ||||||
|     pState = pZip->m_pState; |     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 */ |         /* Source file is too large for non-zip64 */ | ||||||
|         /*return mz_zip_set_error(pZip, MZ_ZIP_ARCHIVE_TOO_LARGE); */ |         /*return mz_zip_set_error(pZip, MZ_ZIP_ARCHIVE_TOO_LARGE); */ | ||||||
| @@ -3508,7 +3550,7 @@ mz_bool mz_zip_writer_add_read_buf_callback(mz_zip_archive *pZip, const char *pA | |||||||
|     } |     } | ||||||
| #endif | #endif | ||||||
|  |  | ||||||
|     if (uncomp_size <= 3) |     if (max_size <= 3) | ||||||
|         level = 0; |         level = 0; | ||||||
|  |  | ||||||
|     if (!mz_zip_writer_write_zeros(pZip, cur_archive_file_ofs, num_alignment_padding_bytes)) |     if (!mz_zip_writer_write_zeros(pZip, cur_archive_file_ofs, num_alignment_padding_bytes)) | ||||||
| @@ -3524,19 +3566,25 @@ mz_bool mz_zip_writer_add_read_buf_callback(mz_zip_archive *pZip, const char *pA | |||||||
|         MZ_ASSERT((cur_archive_file_ofs & (pZip->m_file_offset_alignment - 1)) == 0); |         MZ_ASSERT((cur_archive_file_ofs & (pZip->m_file_offset_alignment - 1)) == 0); | ||||||
|     } |     } | ||||||
|  |  | ||||||
|     if (uncomp_size && level) |     if (max_size && level) | ||||||
|     { |     { | ||||||
|         method = MZ_DEFLATED; |         method = MZ_DEFLATED; | ||||||
|     } |     } | ||||||
|  |  | ||||||
|     MZ_CLEAR_OBJ(local_dir_header); |     MZ_CLEAR_ARR(local_dir_header); | ||||||
|     if (pState->m_zip64) |     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; |             pExtra_data = extra_data; | ||||||
|             extra_size = mz_zip_writer_create_zip64_extra_data(extra_data, (uncomp_size >= MZ_UINT32_MAX) ? &uncomp_size : NULL, |             if (level_and_flags & MZ_ZIP_FLAG_WRITE_HEADER_SET_SIZE) | ||||||
|                                                                (uncomp_size >= MZ_UINT32_MAX) ? &comp_size : NULL, (local_dir_header_ofs >= MZ_UINT32_MAX) ? &local_dir_header_ofs : 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); | ||||||
|  |             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, (mz_uint16)(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)) | ||||||
| @@ -3587,9 +3635,8 @@ mz_bool mz_zip_writer_add_read_buf_callback(mz_zip_archive *pZip, const char *pA | |||||||
|         cur_archive_file_ofs += user_extra_data_len; |         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); |         void *pRead_buf = pZip->m_pAlloc(pZip->m_pAlloc_opaque, 1, MZ_ZIP_MAX_IO_BUF_SIZE); | ||||||
|         if (!pRead_buf) |         if (!pRead_buf) | ||||||
|         { |         { | ||||||
| @@ -3598,19 +3645,27 @@ mz_bool mz_zip_writer_add_read_buf_callback(mz_zip_archive *pZip, const char *pA | |||||||
|  |  | ||||||
|         if (!level) |         if (!level) | ||||||
|         { |         { | ||||||
|             while (uncomp_remaining) |             while (1) | ||||||
|             { |             { | ||||||
|                 mz_uint n = (mz_uint)MZ_MIN((mz_uint64)MZ_ZIP_MAX_IO_BUF_SIZE, uncomp_remaining); |                 size_t n = read_callback(callback_opaque, file_ofs, pRead_buf, MZ_ZIP_MAX_IO_BUF_SIZE); | ||||||
|                 if ((read_callback(callback_opaque, file_ofs, pRead_buf, n) != n) || (pZip->m_pWrite(pZip->m_pIO_opaque, cur_archive_file_ofs, pRead_buf, n) != n)) |                 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); |                     pZip->m_pFree(pZip->m_pAlloc_opaque, pRead_buf); | ||||||
|                     return mz_zip_set_error(pZip, MZ_ZIP_FILE_READ_FAILED); |                     return mz_zip_set_error(pZip, MZ_ZIP_FILE_READ_FAILED); | ||||||
|                 } |                 } | ||||||
| 				file_ofs += n; |                 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_crc32 = (mz_uint32)mz_crc32(uncomp_crc32, (const mz_uint8 *)pRead_buf, n); | ||||||
|                 uncomp_remaining -= n; |  | ||||||
|                 cur_archive_file_ofs += n; |                 cur_archive_file_ofs += n; | ||||||
|             } |             } | ||||||
|  |             uncomp_size = file_ofs; | ||||||
|             comp_size = uncomp_size; |             comp_size = uncomp_size; | ||||||
|         } |         } | ||||||
|         else |         else | ||||||
| @@ -3637,24 +3692,26 @@ mz_bool mz_zip_writer_add_read_buf_callback(mz_zip_archive *pZip, const char *pA | |||||||
|  |  | ||||||
|             for (;;) |             for (;;) | ||||||
|             { |             { | ||||||
|                 size_t in_buf_size = (mz_uint32)MZ_MIN(uncomp_remaining, (mz_uint64)MZ_ZIP_MAX_IO_BUF_SIZE); |  | ||||||
|                 tdefl_status status; |                 tdefl_status status; | ||||||
|                 tdefl_flush flush = TDEFL_NO_FLUSH; |                 tdefl_flush flush = TDEFL_NO_FLUSH; | ||||||
|  |  | ||||||
|                 if (read_callback(callback_opaque, file_ofs, pRead_buf, in_buf_size)!= 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); |                     mz_zip_set_error(pZip, MZ_ZIP_FILE_READ_FAILED); | ||||||
|                     break; |                     break; | ||||||
|                 } |                 } | ||||||
|  |  | ||||||
| 				file_ofs += in_buf_size; |                 file_ofs += n; | ||||||
|                 uncomp_crc32 = (mz_uint32)mz_crc32(uncomp_crc32, (const mz_uint8 *)pRead_buf, in_buf_size); |                 uncomp_crc32 = (mz_uint32)mz_crc32(uncomp_crc32, (const mz_uint8 *)pRead_buf, n); | ||||||
|                 uncomp_remaining -= in_buf_size; |  | ||||||
|  |  | ||||||
|                 if (pZip->m_pNeeds_keepalive != NULL && pZip->m_pNeeds_keepalive(pZip->m_pIO_opaque)) |                 if (pZip->m_pNeeds_keepalive != NULL && pZip->m_pNeeds_keepalive(pZip->m_pIO_opaque)) | ||||||
|                     flush = TDEFL_FULL_FLUSH; |                     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) |                 if (status == TDEFL_STATUS_DONE) | ||||||
|                 { |                 { | ||||||
|                     result = MZ_TRUE; |                     result = MZ_TRUE; | ||||||
| @@ -3675,6 +3732,7 @@ mz_bool mz_zip_writer_add_read_buf_callback(mz_zip_archive *pZip, const char *pA | |||||||
|                 return MZ_FALSE; |                 return MZ_FALSE; | ||||||
|             } |             } | ||||||
|  |  | ||||||
|  |             uncomp_size = file_ofs; | ||||||
|             comp_size = state.m_comp_size; |             comp_size = state.m_comp_size; | ||||||
|             cur_archive_file_ofs = state.m_cur_archive_file_ofs; |             cur_archive_file_ofs = state.m_cur_archive_file_ofs; | ||||||
|         } |         } | ||||||
| @@ -3682,6 +3740,7 @@ mz_bool mz_zip_writer_add_read_buf_callback(mz_zip_archive *pZip, const char *pA | |||||||
|         pZip->m_pFree(pZip->m_pAlloc_opaque, pRead_buf); |         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_uint8 local_dir_footer[MZ_ZIP_DATA_DESCRIPTER_SIZE64]; | ||||||
|         mz_uint32 local_dir_footer_size = MZ_ZIP_DATA_DESCRIPTER_SIZE32; |         mz_uint32 local_dir_footer_size = MZ_ZIP_DATA_DESCRIPTER_SIZE32; | ||||||
| @@ -3709,6 +3768,44 @@ mz_bool mz_zip_writer_add_read_buf_callback(mz_zip_archive *pZip, const char *pA | |||||||
|         cur_archive_file_ofs += local_dir_footer_size; |         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) |     if (pExtra_data != NULL) | ||||||
|     { |     { | ||||||
|         extra_size = mz_zip_writer_create_zip64_extra_data(extra_data, (uncomp_size >= MZ_UINT32_MAX) ? &uncomp_size : NULL, |         extra_size = mz_zip_writer_create_zip64_extra_data(extra_data, (uncomp_size >= MZ_UINT32_MAX) ? &uncomp_size : NULL, | ||||||
| @@ -3739,10 +3836,10 @@ static size_t mz_file_read_func_stdio(void *pOpaque, mz_uint64 file_ofs, void *p | |||||||
| 	return MZ_FREAD(pBuf, 1, n, pSrc_file); | 	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 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_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) | 	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, size_to_add, pFile_time, pComment, comment_size, level_and_flags, | 	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); | 		user_extra_data, user_extra_data_len, user_extra_data_central, user_extra_data_central_len); | ||||||
| } | } | ||||||
|  |  | ||||||
| @@ -3778,7 +3875,7 @@ mz_bool mz_zip_writer_add_file(mz_zip_archive *pZip, const char *pArchive_name, | |||||||
| } | } | ||||||
| #endif /* #ifndef MINIZ_NO_STDIO */ | #endif /* #ifndef MINIZ_NO_STDIO */ | ||||||
|  |  | ||||||
| static mz_bool mz_zip_writer_update_zip64_extension_block(mz_zip_array *pNew_ext, mz_zip_archive *pZip, const mz_uint8 *pExt, uint32_t ext_len, mz_uint64 *pComp_size, mz_uint64 *pUncomp_size, mz_uint64 *pLocal_header_ofs, mz_uint32 *pDisk_start) | static mz_bool mz_zip_writer_update_zip64_extension_block(mz_zip_array *pNew_ext, mz_zip_archive *pZip, const mz_uint8 *pExt, mz_uint32 ext_len, mz_uint64 *pComp_size, mz_uint64 *pUncomp_size, mz_uint64 *pLocal_header_ofs, mz_uint32 *pDisk_start) | ||||||
| { | { | ||||||
|     /* + 64 should be enough for any new zip64 data */ |     /* + 64 should be enough for any new zip64 data */ | ||||||
|     if (!mz_zip_array_reserve(pZip, pNew_ext, ext_len + 64, MZ_FALSE)) |     if (!mz_zip_array_reserve(pZip, pNew_ext, ext_len + 64, MZ_FALSE)) | ||||||
| @@ -4094,10 +4191,10 @@ mz_bool mz_zip_writer_add_from_zip_reader(mz_zip_archive *pZip, mz_zip_archive * | |||||||
|             if (pZip->m_pState->m_zip64) |             if (pZip->m_pState->m_zip64) | ||||||
|             { |             { | ||||||
|                 /* dest is zip64, so upgrade the data descriptor */ |                 /* dest is zip64, so upgrade the data descriptor */ | ||||||
|                 const mz_uint32 *pSrc_descriptor = (const mz_uint32 *)((const mz_uint8 *)pBuf + (has_id ? sizeof(mz_uint32) : 0)); |                 const mz_uint8 *pSrc_descriptor = (const mz_uint8 *)pBuf + (has_id ? sizeof(mz_uint32) : 0); | ||||||
|                 const mz_uint32 src_crc32 = pSrc_descriptor[0]; |                 const mz_uint32 src_crc32 = MZ_READ_LE32(pSrc_descriptor); | ||||||
|                 const mz_uint64 src_comp_size = pSrc_descriptor[1]; |                 const mz_uint64 src_comp_size = MZ_READ_LE32(pSrc_descriptor + sizeof(mz_uint32)); | ||||||
|                 const mz_uint64 src_uncomp_size = pSrc_descriptor[2]; |                 const mz_uint64 src_uncomp_size = MZ_READ_LE32(pSrc_descriptor + 2*sizeof(mz_uint32)); | ||||||
|  |  | ||||||
|                 mz_write_le32((mz_uint8 *)pBuf, MZ_ZIP_DATA_DESCRIPTOR_ID); |                 mz_write_le32((mz_uint8 *)pBuf, MZ_ZIP_DATA_DESCRIPTOR_ID); | ||||||
|                 mz_write_le32((mz_uint8 *)pBuf + sizeof(mz_uint32) * 1, src_crc32); |                 mz_write_le32((mz_uint8 *)pBuf + sizeof(mz_uint32) * 1, src_crc32); | ||||||
| @@ -4233,7 +4330,7 @@ mz_bool mz_zip_writer_finalize_archive(mz_zip_archive *pZip) | |||||||
|  |  | ||||||
|     if (pState->m_zip64) |     if (pState->m_zip64) | ||||||
|     { |     { | ||||||
|         if ((pZip->m_total_files > MZ_UINT32_MAX) || (pState->m_central_dir.m_size >= MZ_UINT32_MAX)) |         if ((mz_uint64)pState->m_central_dir.m_size >= MZ_UINT32_MAX) | ||||||
|             return mz_zip_set_error(pZip, MZ_ZIP_TOO_MANY_FILES); |             return mz_zip_set_error(pZip, MZ_ZIP_TOO_MANY_FILES); | ||||||
|     } |     } | ||||||
|     else |     else | ||||||
| @@ -4261,7 +4358,7 @@ mz_bool mz_zip_writer_finalize_archive(mz_zip_archive *pZip) | |||||||
|         /* Write zip64 end of central directory header */ |         /* Write zip64 end of central directory header */ | ||||||
|         mz_uint64 rel_ofs_to_zip64_ecdr = pZip->m_archive_size; |         mz_uint64 rel_ofs_to_zip64_ecdr = pZip->m_archive_size; | ||||||
|  |  | ||||||
|         MZ_CLEAR_OBJ(hdr); |         MZ_CLEAR_ARR(hdr); | ||||||
|         MZ_WRITE_LE32(hdr + MZ_ZIP64_ECDH_SIG_OFS, MZ_ZIP64_END_OF_CENTRAL_DIR_HEADER_SIG); |         MZ_WRITE_LE32(hdr + MZ_ZIP64_ECDH_SIG_OFS, MZ_ZIP64_END_OF_CENTRAL_DIR_HEADER_SIG); | ||||||
|         MZ_WRITE_LE64(hdr + MZ_ZIP64_ECDH_SIZE_OF_RECORD_OFS, MZ_ZIP64_END_OF_CENTRAL_DIR_HEADER_SIZE - sizeof(mz_uint32) - sizeof(mz_uint64)); |         MZ_WRITE_LE64(hdr + MZ_ZIP64_ECDH_SIZE_OF_RECORD_OFS, MZ_ZIP64_END_OF_CENTRAL_DIR_HEADER_SIZE - sizeof(mz_uint32) - sizeof(mz_uint64)); | ||||||
|         MZ_WRITE_LE16(hdr + MZ_ZIP64_ECDH_VERSION_MADE_BY_OFS, 0x031E); /* TODO: always Unix */ |         MZ_WRITE_LE16(hdr + MZ_ZIP64_ECDH_VERSION_MADE_BY_OFS, 0x031E); /* TODO: always Unix */ | ||||||
| @@ -4276,7 +4373,7 @@ mz_bool mz_zip_writer_finalize_archive(mz_zip_archive *pZip) | |||||||
|         pZip->m_archive_size += MZ_ZIP64_END_OF_CENTRAL_DIR_HEADER_SIZE; |         pZip->m_archive_size += MZ_ZIP64_END_OF_CENTRAL_DIR_HEADER_SIZE; | ||||||
|  |  | ||||||
|         /* Write zip64 end of central directory locator */ |         /* Write zip64 end of central directory locator */ | ||||||
|         MZ_CLEAR_OBJ(hdr); |         MZ_CLEAR_ARR(hdr); | ||||||
|         MZ_WRITE_LE32(hdr + MZ_ZIP64_ECDL_SIG_OFS, MZ_ZIP64_END_OF_CENTRAL_DIR_LOCATOR_SIG); |         MZ_WRITE_LE32(hdr + MZ_ZIP64_ECDL_SIG_OFS, MZ_ZIP64_END_OF_CENTRAL_DIR_LOCATOR_SIG); | ||||||
|         MZ_WRITE_LE64(hdr + MZ_ZIP64_ECDL_REL_OFS_TO_ZIP64_ECDR_OFS, rel_ofs_to_zip64_ecdr); |         MZ_WRITE_LE64(hdr + MZ_ZIP64_ECDL_REL_OFS_TO_ZIP64_ECDR_OFS, rel_ofs_to_zip64_ecdr); | ||||||
|         MZ_WRITE_LE32(hdr + MZ_ZIP64_ECDL_TOTAL_NUMBER_OF_DISKS_OFS, 1); |         MZ_WRITE_LE32(hdr + MZ_ZIP64_ECDL_TOTAL_NUMBER_OF_DISKS_OFS, 1); | ||||||
| @@ -4287,7 +4384,7 @@ mz_bool mz_zip_writer_finalize_archive(mz_zip_archive *pZip) | |||||||
|     } |     } | ||||||
|  |  | ||||||
|     /* Write end of central directory record */ |     /* Write end of central directory record */ | ||||||
|     MZ_CLEAR_OBJ(hdr); |     MZ_CLEAR_ARR(hdr); | ||||||
|     MZ_WRITE_LE32(hdr + MZ_ZIP_ECDH_SIG_OFS, MZ_ZIP_END_OF_CENTRAL_DIR_HEADER_SIG); |     MZ_WRITE_LE32(hdr + MZ_ZIP_ECDH_SIG_OFS, MZ_ZIP_END_OF_CENTRAL_DIR_HEADER_SIG); | ||||||
|     MZ_WRITE_LE16(hdr + MZ_ZIP_ECDH_CDIR_NUM_ENTRIES_ON_DISK_OFS, MZ_MIN(MZ_UINT16_MAX, pZip->m_total_files)); |     MZ_WRITE_LE16(hdr + MZ_ZIP_ECDH_CDIR_NUM_ENTRIES_ON_DISK_OFS, MZ_MIN(MZ_UINT16_MAX, pZip->m_total_files)); | ||||||
|     MZ_WRITE_LE16(hdr + MZ_ZIP_ECDH_CDIR_TOTAL_ENTRIES_OFS, MZ_MIN(MZ_UINT16_MAX, pZip->m_total_files)); |     MZ_WRITE_LE16(hdr + MZ_ZIP_ECDH_CDIR_TOTAL_ENTRIES_OFS, MZ_MIN(MZ_UINT16_MAX, pZip->m_total_files)); | ||||||
|   | |||||||
							
								
								
									
										191
									
								
								miniz_zip.h
									
									
									
									
									
								
							
							
						
						
									
										191
									
								
								miniz_zip.h
									
									
									
									
									
								
							| @@ -1,6 +1,6 @@ | |||||||
|  |  | ||||||
| #pragma once | #pragma once | ||||||
| #include "miniz.h" | #include "miniz_common.h" | ||||||
|  |  | ||||||
| /* ------------------- ZIP archive reading/writing */ | /* ------------------- ZIP archive reading/writing */ | ||||||
|  |  | ||||||
| @@ -32,10 +32,6 @@ typedef struct | |||||||
|     mz_uint16 m_bit_flag; |     mz_uint16 m_bit_flag; | ||||||
|     mz_uint16 m_method; |     mz_uint16 m_method; | ||||||
|  |  | ||||||
| #ifndef MINIZ_NO_TIME |  | ||||||
|     MZ_TIME_T m_time; |  | ||||||
| #endif |  | ||||||
|  |  | ||||||
|     /* CRC-32 of uncompressed data. */ |     /* CRC-32 of uncompressed data. */ | ||||||
|     mz_uint32 m_crc32; |     mz_uint32 m_crc32; | ||||||
|  |  | ||||||
| @@ -72,6 +68,11 @@ typedef struct | |||||||
|     /* Guaranteed to be zero terminated, may be truncated to fit. */ |     /* Guaranteed to be zero terminated, may be truncated to fit. */ | ||||||
|     char m_comment[MZ_ZIP_MAX_ARCHIVE_FILE_COMMENT_SIZE]; |     char m_comment[MZ_ZIP_MAX_ARCHIVE_FILE_COMMENT_SIZE]; | ||||||
|  |  | ||||||
|  | #ifdef MINIZ_NO_TIME | ||||||
|  |     MZ_TIME_T m_padding; | ||||||
|  | #else | ||||||
|  |     MZ_TIME_T m_time; | ||||||
|  | #endif | ||||||
| } mz_zip_archive_file_stat; | } mz_zip_archive_file_stat; | ||||||
|  |  | ||||||
| typedef size_t (*mz_file_read_func)(void *pOpaque, mz_uint64 file_ofs, void *pBuf, size_t n); | typedef size_t (*mz_file_read_func)(void *pOpaque, mz_uint64 file_ofs, void *pBuf, size_t n); | ||||||
| @@ -97,7 +98,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_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_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_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; | } mz_zip_flags; | ||||||
|  |  | ||||||
| typedef enum { | typedef enum { | ||||||
| @@ -180,9 +184,7 @@ typedef struct | |||||||
|     mz_uint flags; |     mz_uint flags; | ||||||
|  |  | ||||||
|     int status; |     int status; | ||||||
| #ifndef MINIZ_DISABLE_ZIP_READER_CRC32_CHECKS |  | ||||||
|     mz_uint file_crc32; |  | ||||||
| #endif |  | ||||||
|     mz_uint64 read_buf_size, read_buf_ofs, read_buf_avail, comp_remaining, out_buf_ofs, cur_file_ofs; |     mz_uint64 read_buf_size, read_buf_ofs, read_buf_avail, comp_remaining, out_buf_ofs, cur_file_ofs; | ||||||
|     mz_zip_archive_file_stat file_stat; |     mz_zip_archive_file_stat file_stat; | ||||||
|     void *pRead_buf; |     void *pRead_buf; | ||||||
| @@ -192,149 +194,157 @@ typedef struct | |||||||
|  |  | ||||||
|     tinfl_decompressor inflator; |     tinfl_decompressor inflator; | ||||||
|  |  | ||||||
|  | #ifdef MINIZ_DISABLE_ZIP_READER_CRC32_CHECKS | ||||||
|  |     mz_uint padding; | ||||||
|  | #else | ||||||
|  |     mz_uint file_crc32; | ||||||
|  | #endif | ||||||
|  |  | ||||||
| } mz_zip_reader_extract_iter_state; | } mz_zip_reader_extract_iter_state; | ||||||
|  |  | ||||||
| /* -------- ZIP reading */ | /* -------- ZIP reading */ | ||||||
|  |  | ||||||
| /* Inits a ZIP archive reader. */ | /* Inits a ZIP archive reader. */ | ||||||
| /* These functions read and validate the archive's central directory. */ | /* 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 | #ifndef MINIZ_NO_STDIO | ||||||
| /* Read a archive from a disk file. */ | /* Read a archive from a disk file. */ | ||||||
| /* file_start_ofs is the file offset where the archive actually begins, or 0. */ | /* 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. */ | /* 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); | MINIZ_EXPORT 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_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. */ | /* 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. */ | /* 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 | #endif | ||||||
|  |  | ||||||
| /* Ends archive reading, freeing all allocations, and closing the input archive file if mz_zip_reader_init_file() was used. */ | /* 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 */ | /* -------- ZIP reading or writing */ | ||||||
|  |  | ||||||
| /* Clears a mz_zip_archive struct to all zeros. */ | /* Clears a mz_zip_archive struct to all zeros. */ | ||||||
| /* Important: This must be done before passing the struct to any mz_zip functions. */ | /* 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); | MINIZ_EXPORT 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_type mz_zip_get_type(mz_zip_archive *pZip); | ||||||
|  |  | ||||||
| /* Returns the total number of files in the archive. */ | /* 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); | MINIZ_EXPORT mz_uint64 mz_zip_get_archive_size(mz_zip_archive *pZip); | ||||||
| mz_uint64 mz_zip_get_archive_file_start_offset(mz_zip_archive *pZip); | MINIZ_EXPORT 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_FILE *mz_zip_get_cfile(mz_zip_archive *pZip); | ||||||
|  |  | ||||||
| /* Reads n bytes of raw archive data, starting at file offset file_ofs, to pBuf. */ | /* 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); | 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. */ | /* 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. */ | /* 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); | MINIZ_EXPORT 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); | MINIZ_EXPORT mz_zip_error mz_zip_peek_last_error(mz_zip_archive *pZip); | ||||||
| mz_zip_error mz_zip_clear_last_error(mz_zip_archive *pZip); | MINIZ_EXPORT mz_zip_error mz_zip_clear_last_error(mz_zip_archive *pZip); | ||||||
| mz_zip_error mz_zip_get_last_error(mz_zip_archive *pZip); | MINIZ_EXPORT 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 const char *mz_zip_get_error_string(mz_zip_error mz_err); | ||||||
|  |  | ||||||
| /* MZ_TRUE if the archive file entry is a directory entry. */ | /* 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_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_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. */ | /* 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. */ | /* 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. */ | /* Attempts to locates a file in the archive's central directory. */ | ||||||
| /* Valid flags: MZ_ZIP_FLAG_CASE_SENSITIVE, MZ_ZIP_FLAG_IGNORE_PATH */ | /* Valid flags: MZ_ZIP_FLAG_CASE_SENSITIVE, MZ_ZIP_FLAG_IGNORE_PATH */ | ||||||
| /* Returns -1 if the file cannot be found. */ | /* 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); | MINIZ_EXPORT 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 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. */ | /* 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. */ | /* 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. */ | /* 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. */ | /* Returns the total central directory size in bytes. */ | ||||||
| /* The current max supported size is <= MZ_UINT32_MAX. */ | /* 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. */ | /* 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). */ | /* 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); | 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); | ||||||
| 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_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. */ | /* 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); | 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); | ||||||
| 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_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. */ | /* Extracts a archive file to a dynamically allocated heap buffer. */ | ||||||
| /* The memory will be allocated via the mz_zip_archive's alloc/realloc functions. */ | /* The memory will be allocated via the mz_zip_archive's alloc/realloc functions. */ | ||||||
| /* Returns NULL and sets the last error on failure. */ | /* 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); | MINIZ_EXPORT 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_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. */ | /* 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); | 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); | ||||||
| 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_file_to_callback(mz_zip_archive *pZip, const char *pFilename, mz_file_write_func pCallback, void *pOpaque, mz_uint flags); | ||||||
|  |  | ||||||
| /* Extract a file iteratively */ | /* 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); | 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); | ||||||
| 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 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); | MINIZ_EXPORT 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_bool mz_zip_reader_extract_iter_free(mz_zip_reader_extract_iter_state* pState); | ||||||
|  |  | ||||||
| #ifndef MINIZ_NO_STDIO | #ifndef MINIZ_NO_STDIO | ||||||
| /* Extracts a archive file to a disk file and sets its last accessed and modified times. */ | /* 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. */ | /* 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); | 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); | ||||||
| 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_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. */ | /* 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); | MINIZ_EXPORT 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_file_to_cfile(mz_zip_archive *pZip, const char *pArchive_filename, MZ_FILE *pFile, mz_uint flags); | ||||||
| #endif | #endif | ||||||
|  |  | ||||||
| #if 0 | #if 0 | ||||||
| /* TODO */ | /* TODO */ | ||||||
| 	typedef void *mz_zip_streaming_extract_state_ptr; | 	typedef void *mz_zip_streaming_extract_state_ptr; | ||||||
| 	mz_zip_streaming_extract_state_ptr mz_zip_streaming_extract_begin(mz_zip_archive *pZip, mz_uint file_index, mz_uint flags); | 	mz_zip_streaming_extract_state_ptr mz_zip_streaming_extract_begin(mz_zip_archive *pZip, mz_uint file_index, mz_uint flags); | ||||||
| 	uint64_t mz_zip_streaming_extract_get_size(mz_zip_archive *pZip, mz_zip_streaming_extract_state_ptr pState); | 	mz_uint64 mz_zip_streaming_extract_get_size(mz_zip_archive *pZip, mz_zip_streaming_extract_state_ptr pState); | ||||||
| 	uint64_t mz_zip_streaming_extract_get_cur_ofs(mz_zip_archive *pZip, mz_zip_streaming_extract_state_ptr pState); | 	mz_uint64 mz_zip_streaming_extract_get_cur_ofs(mz_zip_archive *pZip, mz_zip_streaming_extract_state_ptr pState); | ||||||
| 	mz_bool mz_zip_streaming_extract_seek(mz_zip_archive *pZip, mz_zip_streaming_extract_state_ptr pState, uint64_t new_ofs); | 	mz_bool mz_zip_streaming_extract_seek(mz_zip_archive *pZip, mz_zip_streaming_extract_state_ptr pState, mz_uint64 new_ofs); | ||||||
| 	size_t mz_zip_streaming_extract_read(mz_zip_archive *pZip, mz_zip_streaming_extract_state_ptr pState, void *pBuf, size_t buf_size); | 	size_t mz_zip_streaming_extract_read(mz_zip_archive *pZip, mz_zip_streaming_extract_state_ptr pState, void *pBuf, size_t buf_size); | ||||||
| 	mz_bool mz_zip_streaming_extract_end(mz_zip_archive *pZip, mz_zip_streaming_extract_state_ptr pState); | 	mz_bool mz_zip_streaming_extract_end(mz_zip_archive *pZip, mz_zip_streaming_extract_state_ptr pState); | ||||||
| #endif | #endif | ||||||
|  |  | ||||||
| /* 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. */ | /* 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. */ | /* 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. */ | /* 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 */ | /* 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); | MINIZ_EXPORT 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); | #ifndef MINIZ_NO_STDIO | ||||||
|  | MINIZ_EXPORT mz_bool mz_zip_validate_file_archive(const char *pFilename, mz_uint flags, mz_zip_error *pErr); | ||||||
|  | #endif | ||||||
|  |  | ||||||
| /* Universal end function - calls either mz_zip_reader_end() or mz_zip_writer_end(). */ | /* 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 */ | /* -------- ZIP writing */ | ||||||
|  |  | ||||||
| @@ -343,16 +353,16 @@ mz_bool mz_zip_end(mz_zip_archive *pZip); | |||||||
| /* Inits a ZIP archive writer. */ | /* 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*/ | /*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*/ | /*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); | MINIZ_EXPORT 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_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); | 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); | ||||||
| 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_v2(mz_zip_archive *pZip, size_t size_to_reserve_at_beginning, size_t initial_allocation_size, mz_uint flags); | ||||||
|  |  | ||||||
| #ifndef MINIZ_NO_STDIO | #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); | MINIZ_EXPORT 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); | 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); | ||||||
| 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_cfile(mz_zip_archive *pZip, MZ_FILE *pFile, mz_uint flags); | ||||||
| #endif | #endif | ||||||
|  |  | ||||||
| /* Converts a ZIP archive reader object into a writer object, to allow efficient in-place file appends to occur on an existing archive. */ | /* Converts a ZIP archive reader object into a writer object, to allow efficient in-place file appends to occur on an existing archive. */ | ||||||
| @@ -361,56 +371,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. */ | /* 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 */ | /* 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. */ | /* 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); | MINIZ_EXPORT 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_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. */ | /* 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. */ | /* 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. */ | /* 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. */ | /* 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. */ | /* 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, | 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); |                                               mz_uint64 uncomp_size, mz_uint32 uncomp_crc32); | ||||||
|  |  | ||||||
| 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, | 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, |                                                  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); |                                                  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. */ | /* 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.*/ | /* File data is supplied via a read callback function. User mz_zip_writer_add_(c)file to add a file directly.*/ | ||||||
| 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 size_to_add, | 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 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); | 	const char *user_extra_data_central, mz_uint user_extra_data_central_len); | ||||||
|  |  | ||||||
|  |  | ||||||
| #ifndef MINIZ_NO_STDIO | #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. */ | /* 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. */ | /* 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. */ | /* 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 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); |                                 const char *user_extra_data_central, mz_uint user_extra_data_central_len); | ||||||
| #endif | #endif | ||||||
|  |  | ||||||
| /* Adds a file to an archive by fully cloning the data from another archive. */ | /* 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. */ | /* 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. */ | /* 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(). */ | /* 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. */ | /* 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. */ | /* Finalizes a heap archive, returning a pointer to the heap block and its size. */ | ||||||
| /* The heap block will be allocated using the mz_zip_archive's alloc/realloc callbacks. */ | /* 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. */ | /* 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). */ | /* 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: */ | /* -------- Misc. high-level helper functions: */ | ||||||
|  |  | ||||||
| @@ -418,14 +429,16 @@ 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). */ | /* 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. */ | /* 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. */ | /* 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); | 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); | ||||||
| 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_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); | ||||||
|  |  | ||||||
|  | #ifndef MINIZ_NO_STDIO | ||||||
| /* Reads a single file from an archive into a heap block. */ | /* 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. */ | /* If pComment is not NULL, only the file with the specified comment will be extracted. */ | ||||||
| /* Returns NULL on failure. */ | /* 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); | MINIZ_EXPORT 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_v2(const char *pZip_filename, const char *pArchive_name, const char *pComment, size_t *pSize, mz_uint flags, mz_zip_error *pErr); | ||||||
|  | #endif | ||||||
|  |  | ||||||
| #endif /* #ifndef MINIZ_NO_ARCHIVE_WRITING_APIS */ | #endif /* #ifndef MINIZ_NO_ARCHIVE_WRITING_APIS */ | ||||||
|  |  | ||||||
|   | |||||||
| @@ -4,7 +4,7 @@ Miniz is a lossless, high performance data compression library in a single sourc | |||||||
|  |  | ||||||
| ## Usage | ## Usage | ||||||
|  |  | ||||||
| Please use the files from the [releases page](https://github.com/richgel999/miniz/releases) in your projects. Do not use the git checkout directly! The different source and header files are [amalgamated](https://www.sqlite.org/amalgamation.html) into one `miniz.c`/`miniz.h` pair in a build step (`amalgamate.sh`). Include `miniz.c` and `miniz.h` in your project to use Miniz. | Releases are available at the [releases page](https://github.com/richgel999/miniz/releases) as a pair of `miniz.c`/`miniz.h` files which can be simply added to a project. To create this file pair the different source and header files are [amalgamated](https://www.sqlite.org/amalgamation.html) during build. Alternatively use as cmake or meson module (or build system of your choice). | ||||||
|  |  | ||||||
| ## Features | ## Features | ||||||
|  |  | ||||||
| @@ -31,7 +31,4 @@ Thanks to Bruce Dawson for reporting a problem with the level_and_flags archive | |||||||
|  |  | ||||||
| ## Patents | ## Patents | ||||||
|  |  | ||||||
| I was recently asked if miniz avoids patent issues. miniz purposely uses the same core algorithms as the ones used by zlib. The compressor uses vanilla hash chaining as described [here](http://www.gzip.org/zlib/rfc-deflate.html#algorithm). Also see the [gzip FAQ](http://www.gzip.org/#faq11). In my opinion, if miniz falls prey to a patent attack then zlib/gzip are likely to be at serious risk too. | I was recently asked if miniz avoids patent issues. miniz purposely uses the same core algorithms as the ones used by zlib. The compressor uses vanilla hash chaining as described [here](https://datatracker.ietf.org/doc/html/rfc1951#section-4). Also see the [gzip FAQ](https://web.archive.org/web/20160308045258/http://www.gzip.org/#faq11). In my opinion, if miniz falls prey to a patent attack then zlib/gzip are likely to be at serious risk too. | ||||||
|  |  | ||||||
|  |  | ||||||
| [](https://travis-ci.org/uroni/miniz) |  | ||||||
|   | |||||||
							
								
								
									
										5
									
								
								test.sh
									
									
									
									
									
								
							
							
						
						
									
										5
									
								
								test.sh
									
									
									
									
									
								
							| @@ -4,6 +4,11 @@ set -e | |||||||
|  |  | ||||||
| . amalgamate.sh | . amalgamate.sh | ||||||
|  |  | ||||||
|  | cat << "EOF" > miniz_export.h | ||||||
|  | #ifndef MINIZ_EXPORT | ||||||
|  | #define MINIZ_EXPORT | ||||||
|  | #endif | ||||||
|  | EOF | ||||||
| g++ tests/miniz_tester.cpp tests/timer.cpp amalgamation/miniz.c -o miniz_tester -I. -ggdb -O2 | g++ tests/miniz_tester.cpp tests/timer.cpp amalgamation/miniz.c -o miniz_tester -I. -ggdb -O2 | ||||||
|  |  | ||||||
| for i in 1 2 3 4 5 6 | for i in 1 2 3 4 5 6 | ||||||
|   | |||||||
							
								
								
									
										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