Skip to content

Commit 46f016d

Browse files
larryliu0820pobin6
authored and
pobin6
committed
[miniz] Bump miniz version to 3.0.2 and add patch for zip64 (pytorch#140041)
Summary: Bump miniz version from 2.1.0 to 3.0.2 and apply these patches: * pytorch#79636 patches internal BUCK and bazel build * pytorch#138959 adds `bool compute_crc32` argument * miniz PR: richgel999/miniz#324 to support zip64 Anyone bumping miniz version again, please apply these patches as well. Test Plan: Rely on unit test Imported from OSS Differential Revision: D65586230 Pull Request resolved: pytorch#140041 Approved by: https://github.com/mikaylagawarecki
1 parent a33bc50 commit 46f016d

18 files changed

+703
-356
lines changed

BUILD.bazel

+1-1
Original file line numberDiff line numberDiff line change
@@ -552,7 +552,7 @@ cc_library(
552552
":caffe2_headers",
553553
":caffe2_perfkernels_avx",
554554
":caffe2_perfkernels_avx2",
555-
"//third_party/miniz-2.1.0:miniz",
555+
"//third_party/miniz-3.0.2:miniz",
556556
"@com_google_protobuf//:protobuf",
557557
"@eigen",
558558
"@fbgemm//:fbgemm_src_headers",

buckbuild.bzl

+1-1
Original file line numberDiff line numberDiff line change
@@ -2040,7 +2040,7 @@ def define_buck_targets(
20402040
("", "torch/csrc/utils/*.h"),
20412041
("", "aten/src/ATen/quantized/*.h"),
20422042
] + ([
2043-
("third_party/miniz-2.1.0", "*.h"),
2043+
("third_party/miniz-3.0.2", "*.h"),
20442044
] if NOT_OSS else []),
20452045
exclude = [
20462046
"torch/csrc/jit/serialization/mobile_bytecode_generated.h",

build.bzl

+1-1
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ def define_targets(rules):
4747
deps = [
4848
":caffe2_headers",
4949
"//c10",
50-
"//third_party/miniz-2.1.0:miniz",
50+
"//third_party/miniz-3.0.2:miniz",
5151
"@com_github_glog//:glog",
5252
],
5353
)

caffe2/CMakeLists.txt

+1-1
Original file line numberDiff line numberDiff line change
@@ -1213,7 +1213,7 @@ target_include_directories(torch_cpu PRIVATE
12131213
${TORCH_SRC_DIR}/csrc)
12141214

12151215
target_include_directories(torch_cpu PRIVATE
1216-
${TORCH_ROOT}/third_party/miniz-2.1.0)
1216+
${TORCH_ROOT}/third_party/miniz-3.0.2)
12171217

12181218
target_include_directories(torch_cpu PRIVATE
12191219
${TORCH_ROOT}/third_party/kineto/libkineto/include)

caffe2/serialize/CMakeLists.txt

+2-2
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,13 @@ file(GLOB tmp *_test.cc)
22

33
set(Caffe2_CPU_TEST_SRCS ${Caffe2_CPU_TEST_SRCS} ${tmp})
44
list(APPEND Caffe2_CPU_SRCS
5-
${PROJECT_SOURCE_DIR}/third_party/miniz-2.1.0/miniz.c
5+
${PROJECT_SOURCE_DIR}/third_party/miniz-3.0.2/miniz.c
66
${CMAKE_CURRENT_SOURCE_DIR}/inline_container.cc
77
${CMAKE_CURRENT_SOURCE_DIR}/istream_adapter.cc
88
${CMAKE_CURRENT_SOURCE_DIR}/file_adapter.cc
99
${CMAKE_CURRENT_SOURCE_DIR}/crc.cc
1010
${CMAKE_CURRENT_SOURCE_DIR}/read_adapter_interface.cc)
11-
list(APPEND Caffe2_CPU_INCLUDE ${PROJECT_SOURCE_DIR}/third_party/miniz-2.1.0)
11+
list(APPEND Caffe2_CPU_INCLUDE ${PROJECT_SOURCE_DIR}/third_party/miniz-3.0.2)
1212

1313
set(Caffe2_CPU_TEST_SRCS ${Caffe2_CPU_TEST_SRCS} PARENT_SCOPE)
1414
set(Caffe2_CPU_SRCS ${Caffe2_CPU_SRCS} PARENT_SCOPE)

third_party/BUCK.oss

+4-2
Original file line numberDiff line numberDiff line change
@@ -191,9 +191,11 @@ cxx_library(
191191

192192
cxx_library(
193193
name = "miniz",
194-
srcs = ["miniz-2.1.0/miniz.c"],
194+
srcs = [
195+
"miniz-3.0.2/miniz.c",
196+
],
195197
header_namespace = "",
196-
exported_headers = {"miniz.h": "miniz-2.1.0/miniz.h"},
198+
exported_headers = {"miniz.h": "miniz-3.0.2/miniz.h"},
197199
exported_preprocessor_flags = [
198200
"-DMINIZ_DISABLE_ZIP_READER_CRC32_CHECKS",
199201
],
File renamed without changes.

third_party/miniz-2.1.0/ChangeLog.md third_party/miniz-3.0.2/ChangeLog.md

+65-4
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,68 @@
11
## Changelog
22

3+
### 3.0.2
4+
5+
- Fix buffer overrun in mz_utf8z_to_widechar on Windows
6+
7+
### 3.0.1
8+
9+
- Fix compilation error with MINIZ_USE_UNALIGNED_LOADS_AND_STORES=1
10+
11+
### 3.0.0
12+
13+
- Reduce memory usage for inflate. This changes `struct tinfl_decompressor_tag` and therefore requires a major version bump (breaks ABI compatibility)
14+
- Add padding to structures so it continues to work if features differ. This also changes some structures
15+
- Use _ftelli64, _fseeki64 and stat with MinGW32 and OpenWatcom
16+
- Fix varios warnings with OpenWatcom compiler
17+
- Avoid using unaligned memory access in UBSan builds
18+
- Set MINIZ_LITTLE_ENDIAN only if not set
19+
- Add MINIZ_NO_DEFLATE_APIS and MINIZ_NO_INFLATE_APIS
20+
- Fix use of uninitialized memory in tinfl_decompress_mem_to_callback()
21+
- Use wfopen on windows
22+
- Use _wstat64 instead _stat64 on windows
23+
- Use level_and_flags after MZ_DEFAULT_COMPRESSION has been handled
24+
- Improve endianess detection
25+
- Don't use unaligned stores and loads per default
26+
- Fix function declaration if MINIZ_NO_STDIO is used
27+
- Fix MZ_ZIP_GENERAL_PURPOSE_BIT_FLAG_UTF8 not being set
28+
- Remove total files check (its 32-bit uint)
29+
- tinfl_decompress: avoid NULL ptr arithmetic UB
30+
- miniz_zip: fix mz_zip_reader_extract_to_heap to read correct sizes
31+
- Eliminate 64-bit operations on 32-bit machines
32+
- Disable treating warnings as error with MSVC
33+
- Disable building shared lib via CMake by default
34+
- Fixed alignment problems on MacOS
35+
- Fixed get error string for MZ_ZIP_TOTAL_ERRORS
36+
- Write correct FLEVEL 2-bit value in zlib header
37+
- miniz.pc.in: fix include path not containing the "miniz" suffix
38+
- Fix compatibility with FreeBSD
39+
- pkg-config tweaks
40+
- Fix integer overflow in header corruption check
41+
- Fix some warnings
42+
- tdefl_compress_normal: Avoid NULL ptr arithmetic UB
43+
- replace use of stdint.h types with mz_ variants
44+
45+
46+
### 2.2.0
47+
48+
- Fix examples with amalgamation
49+
- Modified cmake script to support shared library mode and find_package
50+
- Fix for misleading doc comment on `mz_zip_reader_init_cfile` function
51+
- Add include location tolerance and stop forcing `_GNU_SOURCE`
52+
- Fix: mz_zip_reader_locate_file_v2 returns an mz_bool
53+
- Fix large file system checks
54+
- Add #elif to enable an external mz_crc32() to be linked in
55+
- Write with dynamic size (size of file/data to be added not known before adding)
56+
- Added uncompress2 for zlib compatibility
57+
- Add support for building as a Meson subproject
58+
- Added OSSFuzz support; Integrate with CIFuzz
59+
- Add pkg-config file
60+
- Fixed use-of-uninitialized value msan error when copying dist bytes with no output bytes written.
61+
- mz_zip_validate_file(): fix memory leak on errors
62+
- 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
63+
- Add flag to set (compressed) size in local file header
64+
- avoid use of uninitialized value in tdefl_record_literal
65+
366
### 2.1.0
467

568
- More instances of memcpy instead of cast and use memcpy per default
@@ -82,7 +145,7 @@ The inflator now has a new failure status TINFL_STATUS_FAILED_CANNOT_MAKE_PROGRE
82145
- 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.
83146
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
84147
going to mark this release as beta for a few weeks and continue testing it at work/home on various things.
85-
- 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).
148+
- 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).
86149
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
87150
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).
88151
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 +166,7 @@ Merged over a few very minor bug fixes that I fixed in the zip64 branch. This is
103166
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 [email protected]), 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.
104167

105168
- Critical fix for the MZ_ZIP_FLAG_DO_NOT_SORT_CENTRAL_DIRECTORY bug (thanks [email protected]) which could cause locate files to not find files. This bug
106-
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()
169+
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()
107170
(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).
108171
- 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
109172
- 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.
@@ -172,5 +235,3 @@ Added statement from unlicense.org
172235
### v1.09 - 5/15/11
173236

174237
Initial stable release.
175-
176-
File renamed without changes.

third_party/miniz-2.1.0/examples/example2.c third_party/miniz-3.0.2/examples/example2.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
#endif
1414

1515
#include <stdio.h>
16-
#include "miniz_zip.h"
16+
#include "miniz.h"
1717

1818
typedef unsigned char uint8;
1919
typedef unsigned short uint16;

third_party/miniz-2.1.0/examples/example3.c third_party/miniz-3.0.2/examples/example3.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ int main(int argc, char *argv[])
100100
file_loc = ftell(pInfile);
101101
fseek(pInfile, 0, SEEK_SET);
102102

103-
if ((file_loc < 0) || (file_loc > INT_MAX))
103+
if ((file_loc < 0) || ((mz_uint64)file_loc > INT_MAX))
104104
{
105105
// This is not a limitation of miniz or tinfl, but this example.
106106
printf("File is too large to be processed by this example.\n");

third_party/miniz-2.1.0/examples/example4.c third_party/miniz-3.0.2/examples/example4.c

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
// example4.c - Uses tinfl.c to decompress a zlib stream in memory to an output file
22
// Public domain, May 15 2011, Rich Geldreich, [email protected]. See "unlicense" statement at the end of tinfl.c.
3-
#include "miniz_tinfl.h"
3+
#include "miniz.h"
44
#include <stdio.h>
55
#include <limits.h>
66

@@ -47,7 +47,7 @@ int main(int argc, char *argv[])
4747
file_loc = ftell(pInfile);
4848
fseek(pInfile, 0, SEEK_SET);
4949

50-
if ((file_loc < 0) || (file_loc > INT_MAX))
50+
if ((file_loc < 0) || ((mz_uint64)file_loc > INT_MAX))
5151
{
5252
// This is not a limitation of miniz or tinfl, but this example.
5353
printf("File is too large to be processed by this example.\n");

third_party/miniz-2.1.0/examples/example5.c third_party/miniz-3.0.2/examples/example5.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,7 @@ int main(int argc, char *argv[])
132132
file_loc = ftell(pInfile);
133133
fseek(pInfile, 0, SEEK_SET);
134134

135-
if ((file_loc < 0) || (file_loc > INT_MAX))
135+
if ((file_loc < 0) || ((mz_uint64)file_loc > INT_MAX))
136136
{
137137
// This is not a limitation of miniz or tinfl, but this example.
138138
printf("File is too large to be processed by this example.\n");

third_party/miniz-2.1.0/examples/example6.c third_party/miniz-3.0.2/examples/example6.c

+21-17
Original file line numberDiff line numberDiff line change
@@ -34,27 +34,29 @@ static void hsv_to_rgb(int hue, int min, int max, rgb_t *p)
3434
if (!saturation) {
3535
p->r = p->g = p->b = 255 * (max - hue) / (max - min);
3636
return;
37-
}
38-
double h = fmod(color_rotate + 1e-4 + 4.0 * (hue - min) / (max - min), 6);
39-
double c = 255.0f * saturation;
40-
double X = c * (1 - fabs(fmod(h, 2) - 1));
41-
42-
p->r = p->g = p->b = 0;
43-
44-
switch((int)h) {
45-
case 0: p->r = c; p->g = X; return;
46-
case 1: p->r = X; p->g = c; return;
47-
case 2: p->g = c; p->b = X; return;
48-
case 3: p->g = X; p->b = c; return;
49-
case 4: p->r = X; p->b = c; return;
50-
default:p->r = c; p->b = X;
37+
} else {
38+
const double h_dbl = fmod(color_rotate + 1e-4 + 4.0 * (hue - min) / (max - min), 6);
39+
const double c_dbl = 255 * saturation;
40+
const double X_dbl = c_dbl * (1 - fabs(fmod(h_dbl, 2) - 1));
41+
const int h = (int)h_dbl;
42+
const int c = (int)c_dbl;
43+
const int X = (int)X_dbl;
44+
45+
p->r = p->g = p->b = 0;
46+
47+
switch(h) {
48+
case 0: p->r = c; p->g = X; return;
49+
case 1: p->r = X; p->g = c; return;
50+
case 2: p->g = c; p->b = X; return;
51+
case 3: p->g = X; p->b = c; return;
52+
case 4: p->r = X; p->b = c; return;
53+
default:p->r = c; p->b = X;
54+
}
5155
}
5256
}
5357

5458
int main(int argc, char *argv[])
5559
{
56-
(void)argc, (void)argv;
57-
5860
// Image resolution
5961
const int iXmax = 4096;
6062
const int iYmax = 4096;
@@ -89,6 +91,8 @@ int main(int argc, char *argv[])
8991

9092
int MinIter = 9999, MaxIter = 0;
9193

94+
(void)argc, (void)argv;
95+
9296
for(iY = 0; iY < iYmax; iY++)
9397
{
9498
Cy = CyMin + iY * PixelHeight;
@@ -134,7 +138,7 @@ int main(int argc, char *argv[])
134138

135139
uint Iterations = color[0] | (color[1] << 8U);
136140

137-
hsv_to_rgb(Iterations, MinIter, MaxIter, (rgb_t *)color);
141+
hsv_to_rgb((int)Iterations, MinIter, MaxIter, (rgb_t *)color);
138142
}
139143
}
140144

0 commit comments

Comments
 (0)