Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 970ecf6

Browse files
authored
[release/7.0] Upgrade zlib to 1.3.1 (#99474)
* [7.0] Upgrade zlib to 1.3.1 * Bring in patch to remove implicit narrowing conversions from zlib * [PATCH] Make zlib compile clean against C4244 clang equivalent is "implicit-int-conversion" warning The change to deflate.c is legal because 'len' has an upper bound of MAX_STORED, which means it fits cleanly into a 16-bit integer. So writing out 2x 8-bit values will not result in data loss. The change to trees.c is legal because within this loop, 'count' is intended to have an upper bound of 138, with the target assignment only executing if 'count' is bounded by 4. Neither the 'count' local in isolation nor the addition that's part of the target line is expected to result in integer overflow. But even if it did, that's a matter for a different warning code and doesn't impact the correctness of the narrowing cast being considered here. Author: Levi Broderick <[email protected]> * Update cgmanifest.json and THIRD-PARTY-NOTICES.TXT * Bring back patches comment, remove unnecessary file removal comment.
1 parent b880b97 commit 970ecf6

37 files changed

+1195
-1790
lines changed

THIRD-PARTY-NOTICES.TXT

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ https://github.com/madler/zlib
7373
https://zlib.net/zlib_license.html
7474

7575
/* zlib.h -- interface of the 'zlib' general purpose compression library
76-
version 1.2.13, October 13th, 2022
76+
version 1.3.1, January 22nd, 2024
7777

7878
Copyright (C) 1995-2022 Jean-loup Gailly and Mark Adler
7979

src/native/external/cgmanifest.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@
4545
"Type": "git",
4646
"Git": {
4747
"RepositoryUrl": "https://github.com/madler/zlib",
48-
"CommitHash": "04f42ceca40f73e2978b50e93806c2a18c1281fc"
48+
"CommitHash": "51b7f2abdade71cd9bb0e7a373ef2610ec6f9daf"
4949
}
5050
},
5151
"DevelopmentDependency": false
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
From 86d96652ddd60f61dc7b0c94b601f6d156d34632 Mon Sep 17 00:00:00 2001
2+
From: Levi Broderick <[email protected]>
3+
Date: Mon, 28 Aug 2023 15:26:38 -0700
4+
Subject: [PATCH] Make zlib compile clean against C4244 clang equivalent is
5+
"implicit-int-conversion" warning
6+
7+
The change to deflate.c is legal because 'len' has an upper bound of
8+
MAX_STORED, which means it fits cleanly into a 16-bit integer. So
9+
writing out 2x 8-bit values will not result in data loss.
10+
11+
The change to trees.c is legal because within this loop, 'count' is
12+
intended to have an upper bound of 138, with the target assignment
13+
only executing if 'count' is bounded by 4. Neither the 'count' local
14+
in isolation nor the addition that's part of the target line is
15+
expected to result in integer overflow. But even if it did, that's a
16+
matter for a different warning code and doesn't impact the correctness
17+
of the narrowing cast being considered here.
18+
---
19+
src/native/external/zlib/deflate.c | 8 ++++----
20+
src/native/external/zlib/trees.c | 2 +-
21+
2 files changed, 5 insertions(+), 5 deletions(-)
22+
23+
diff --git a/src/native/external/zlib/deflate.c b/src/native/external/zlib/deflate.c
24+
index d2e1106ef5d..b7636639754 100644
25+
--- a/src/native/external/zlib/deflate.c
26+
+++ b/src/native/external/zlib/deflate.c
27+
@@ -1738,10 +1738,10 @@ local block_state deflate_stored(s, flush)
28+
_tr_stored_block(s, (char *)0, 0L, last);
29+
30+
/* Replace the lengths in the dummy stored block with len. */
31+
- s->pending_buf[s->pending - 4] = len;
32+
- s->pending_buf[s->pending - 3] = len >> 8;
33+
- s->pending_buf[s->pending - 2] = ~len;
34+
- s->pending_buf[s->pending - 1] = ~len >> 8;
35+
+ s->pending_buf[s->pending - 4] = (Bytef)len;
36+
+ s->pending_buf[s->pending - 3] = (Bytef)(len >> 8);
37+
+ s->pending_buf[s->pending - 2] = (Bytef)~len;
38+
+ s->pending_buf[s->pending - 1] = (Bytef)(~len >> 8);
39+
40+
/* Write the stored block header bytes. */
41+
flush_pending(s->strm);
42+
diff --git a/src/native/external/zlib/trees.c b/src/native/external/zlib/trees.c
43+
index 5f305c47221..8a3eec559e5 100644
44+
--- a/src/native/external/zlib/trees.c
45+
+++ b/src/native/external/zlib/trees.c
46+
@@ -721,7 +721,7 @@ local void scan_tree(s, tree, max_code)
47+
if (++count < max_count && curlen == nextlen) {
48+
continue;
49+
} else if (count < min_count) {
50+
- s->bl_tree[curlen].Freq += count;
51+
+ s->bl_tree[curlen].Freq += (ush)count;
52+
} else if (curlen != 0) {
53+
if (curlen != prevlen) s->bl_tree[curlen].Freq++;
54+
s->bl_tree[REP_3_6].Freq++;
55+
--
56+
2.42.0.windows.1
57+
Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,9 @@
1-
v1.2.13
2-
(04f42ceca40f73e2978b50e93806c2a18c1281fc)
1+
v1.3.1
2+
(51b7f2abdade71cd9bb0e7a373ef2610ec6f9daf)
33

4-
https://github.com/madler/zlib/releases/tag/v1.2.13
4+
https://github.com/madler/zlib/releases/tag/v1.3.1
55

66
We have removed zlib.3.pdf from our local copy, as it is a binary file which is
77
not needed for our compilation.
88

9-
We have also cherry-picked into our local copy:
10-
11-
- https://github.com/madler/zlib/commit/e554695638228b846d49657f31eeff0ca4680e8a
12-
13-
This patch only affects memLevel 9 compression. .NET doesn't currently use this
14-
memLevel, but we'll take this patch out of an abundance of caution just in case
15-
we enable this functionality in a future release.
9+
We have also applied the custom patches under the patches/zlib folder.

src/native/external/zlib/CMakeLists.txt

Lines changed: 25 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
1-
cmake_minimum_required(VERSION 2.4.4)
1+
cmake_minimum_required(VERSION 2.4.4...3.15.0)
22
set(CMAKE_ALLOW_LOOSE_LOOP_CONSTRUCTS ON)
33

44
project(zlib C)
55

6-
set(VERSION "1.2.13")
6+
set(VERSION "1.3.1")
7+
8+
option(ZLIB_BUILD_EXAMPLES "Enable Zlib Examples" ON)
79

810
set(INSTALL_BIN_DIR "${CMAKE_INSTALL_PREFIX}/bin" CACHE PATH "Installation directory for executables")
911
set(INSTALL_LIB_DIR "${CMAKE_INSTALL_PREFIX}/lib" CACHE PATH "Installation directory for libraries")
@@ -148,7 +150,9 @@ if(MINGW)
148150
endif(MINGW)
149151

150152
add_library(zlib SHARED ${ZLIB_SRCS} ${ZLIB_DLL_SRCS} ${ZLIB_PUBLIC_HDRS} ${ZLIB_PRIVATE_HDRS})
153+
target_include_directories(zlib PUBLIC ${CMAKE_CURRENT_BINARY_DIR} ${CMAKE_CURRENT_SOURCE_DIR})
151154
add_library(zlibstatic STATIC ${ZLIB_SRCS} ${ZLIB_PUBLIC_HDRS} ${ZLIB_PRIVATE_HDRS})
155+
target_include_directories(zlibstatic PUBLIC ${CMAKE_CURRENT_BINARY_DIR} ${CMAKE_CURRENT_SOURCE_DIR})
152156
set_target_properties(zlib PROPERTIES DEFINE_SYMBOL ZLIB_DLL)
153157
set_target_properties(zlib PROPERTIES SOVERSION 1)
154158

@@ -166,7 +170,7 @@ endif()
166170
if(UNIX)
167171
# On unix-like platforms the library is almost always called libz
168172
set_target_properties(zlib zlibstatic PROPERTIES OUTPUT_NAME z)
169-
if(NOT APPLE)
173+
if(NOT APPLE AND NOT(CMAKE_SYSTEM_NAME STREQUAL AIX))
170174
set_target_properties(zlib PROPERTIES LINK_FLAGS "-Wl,--version-script,\"${CMAKE_CURRENT_SOURCE_DIR}/zlib.map\"")
171175
endif()
172176
elseif(BUILD_SHARED_LIBS AND WIN32)
@@ -193,21 +197,22 @@ endif()
193197
#============================================================================
194198
# Example binaries
195199
#============================================================================
196-
197-
add_executable(example test/example.c)
198-
target_link_libraries(example zlib)
199-
add_test(example example)
200-
201-
add_executable(minigzip test/minigzip.c)
202-
target_link_libraries(minigzip zlib)
203-
204-
if(HAVE_OFF64_T)
205-
add_executable(example64 test/example.c)
206-
target_link_libraries(example64 zlib)
207-
set_target_properties(example64 PROPERTIES COMPILE_FLAGS "-D_FILE_OFFSET_BITS=64")
208-
add_test(example64 example64)
209-
210-
add_executable(minigzip64 test/minigzip.c)
211-
target_link_libraries(minigzip64 zlib)
212-
set_target_properties(minigzip64 PROPERTIES COMPILE_FLAGS "-D_FILE_OFFSET_BITS=64")
200+
if(ZLIB_BUILD_EXAMPLES)
201+
add_executable(example test/example.c)
202+
target_link_libraries(example zlib)
203+
add_test(example example)
204+
205+
add_executable(minigzip test/minigzip.c)
206+
target_link_libraries(minigzip zlib)
207+
208+
if(HAVE_OFF64_T)
209+
add_executable(example64 test/example.c)
210+
target_link_libraries(example64 zlib)
211+
set_target_properties(example64 PROPERTIES COMPILE_FLAGS "-D_FILE_OFFSET_BITS=64")
212+
add_test(example64 example64)
213+
214+
add_executable(minigzip64 test/minigzip.c)
215+
target_link_libraries(minigzip64 zlib)
216+
set_target_properties(minigzip64 PROPERTIES COMPILE_FLAGS "-D_FILE_OFFSET_BITS=64")
217+
endif()
213218
endif()

src/native/external/zlib/ChangeLog

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,34 @@
11

22
ChangeLog file for zlib
33

4+
Changes in 1.3.1 (22 Jan 2024)
5+
- Reject overflows of zip header fields in minizip
6+
- Fix bug in inflateSync() for data held in bit buffer
7+
- Add LIT_MEM define to use more memory for a small deflate speedup
8+
- Fix decision on the emission of Zip64 end records in minizip
9+
- Add bounds checking to ERR_MSG() macro, used by zError()
10+
- Neutralize zip file traversal attacks in miniunz
11+
- Fix a bug in ZLIB_DEBUG compiles in check_match()
12+
- Various portability and appearance improvements
13+
14+
Changes in 1.3 (18 Aug 2023)
15+
- Remove K&R function definitions and zlib2ansi
16+
- Fix bug in deflateBound() for level 0 and memLevel 9
17+
- Fix bug when gzungetc() is used immediately after gzopen()
18+
- Fix bug when using gzflush() with a very small buffer
19+
- Fix crash when gzsetparams() attempted for transparent write
20+
- Fix test/example.c to work with FORCE_STORED
21+
- Rewrite of zran in examples (see zran.c version history)
22+
- Fix minizip to allow it to open an empty zip file
23+
- Fix reading disk number start on zip64 files in minizip
24+
- Fix logic error in minizip argument processing
25+
- Add minizip testing to Makefile
26+
- Read multiple bytes instead of byte-by-byte in minizip unzip.c
27+
- Add memory sanitizer to configure (--memory)
28+
- Various portability improvements
29+
- Various documentation improvements
30+
- Various spelling and typo corrections
31+
432
Changes in 1.2.13 (13 Oct 2022)
533
- Fix configure issue that discarded provided CC definition
634
- Correct incorrect inputs provided to the CRC functions
@@ -1445,7 +1473,7 @@ Changes in 0.99 (27 Jan 96)
14451473
- fix typo in Make_vms.com (f$trnlnm -> f$getsyi)
14461474
- in fcalloc, normalize pointer if size > 65520 bytes
14471475
- don't use special fcalloc for 32 bit Borland C++
1448-
- use STDC instead of __GO32__ to avoid redeclaring exit, calloc, etc...
1476+
- use STDC instead of __GO32__ to avoid redeclaring exit, calloc, etc.
14491477
- use Z_BINARY instead of BINARY
14501478
- document that gzclose after gzdopen will close the file
14511479
- allow "a" as mode in gzopen

src/native/external/zlib/FAQ

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
If your question is not there, please check the zlib home page
66
http://zlib.net/ which may have more recent information.
7-
The lastest zlib FAQ is at http://zlib.net/zlib_faq.html
7+
The latest zlib FAQ is at http://zlib.net/zlib_faq.html
88

99

1010
1. Is zlib Y2K-compliant?
@@ -14,8 +14,7 @@ The lastest zlib FAQ is at http://zlib.net/zlib_faq.html
1414
2. Where can I get a Windows DLL version?
1515

1616
The zlib sources can be compiled without change to produce a DLL. See the
17-
file win32/DLL_FAQ.txt in the zlib distribution. Pointers to the
18-
precompiled DLL are found in the zlib web site at http://zlib.net/ .
17+
file win32/DLL_FAQ.txt in the zlib distribution.
1918

2019
3. Where can I get a Visual Basic interface to zlib?
2120

src/native/external/zlib/Makefile.in

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# Makefile for zlib
2-
# Copyright (C) 1995-2017 Jean-loup Gailly, Mark Adler
2+
# Copyright (C) 1995-2024 Jean-loup Gailly, Mark Adler
33
# For conditions of distribution and use, see copyright notice in zlib.h
44

55
# To compile and test, type:
@@ -22,13 +22,13 @@ CFLAGS=-O
2222

2323
SFLAGS=-O
2424
LDFLAGS=
25-
TEST_LDFLAGS=$(LDFLAGS) -L. libz.a
25+
TEST_LIBS=-L. libz.a
2626
LDSHARED=$(CC)
2727
CPP=$(CC) -E
2828

2929
STATICLIB=libz.a
3030
SHAREDLIB=libz.so
31-
SHAREDLIBV=libz.so.1.2.13
31+
SHAREDLIBV=libz.so.1.3.1
3232
SHAREDLIBM=libz.so.1
3333
LIBS=$(STATICLIB) $(SHAREDLIBV)
3434

@@ -282,10 +282,10 @@ placebo $(SHAREDLIBV): $(PIC_OBJS) libz.a
282282
-@rmdir objs
283283

284284
example$(EXE): example.o $(STATICLIB)
285-
$(CC) $(CFLAGS) -o $@ example.o $(TEST_LDFLAGS)
285+
$(CC) $(CFLAGS) $(LDFLAGS) -o $@ example.o $(TEST_LIBS)
286286

287287
minigzip$(EXE): minigzip.o $(STATICLIB)
288-
$(CC) $(CFLAGS) -o $@ minigzip.o $(TEST_LDFLAGS)
288+
$(CC) $(CFLAGS) $(LDFLAGS) -o $@ minigzip.o $(TEST_LIBS)
289289

290290
examplesh$(EXE): example.o $(SHAREDLIBV)
291291
$(CC) $(CFLAGS) -o $@ example.o $(LDFLAGS) -L. $(SHAREDLIBV)
@@ -294,10 +294,10 @@ minigzipsh$(EXE): minigzip.o $(SHAREDLIBV)
294294
$(CC) $(CFLAGS) -o $@ minigzip.o $(LDFLAGS) -L. $(SHAREDLIBV)
295295

296296
example64$(EXE): example64.o $(STATICLIB)
297-
$(CC) $(CFLAGS) -o $@ example64.o $(TEST_LDFLAGS)
297+
$(CC) $(CFLAGS) $(LDFLAGS) -o $@ example64.o $(TEST_LIBS)
298298

299299
minigzip64$(EXE): minigzip64.o $(STATICLIB)
300-
$(CC) $(CFLAGS) -o $@ minigzip64.o $(TEST_LDFLAGS)
300+
$(CC) $(CFLAGS) $(LDFLAGS) -o $@ minigzip64.o $(TEST_LIBS)
301301

302302
install-libs: $(LIBS)
303303
-@if [ ! -d $(DESTDIR)$(exec_prefix) ]; then mkdir -p $(DESTDIR)$(exec_prefix); fi
@@ -359,8 +359,14 @@ zconf.h.cmakein: $(SRCDIR)zconf.h.in
359359
zconf: $(SRCDIR)zconf.h.in
360360
cp -p $(SRCDIR)zconf.h.in zconf.h
361361

362+
minizip-test: static
363+
cd contrib/minizip && { CC="$(CC)" CFLAGS="$(CFLAGS)" $(MAKE) test ; cd ../.. ; }
364+
365+
minizip-clean:
366+
cd contrib/minizip && { $(MAKE) clean ; cd ../.. ; }
367+
362368
mostlyclean: clean
363-
clean:
369+
clean: minizip-clean
364370
rm -f *.o *.lo *~ \
365371
example$(EXE) minigzip$(EXE) examplesh$(EXE) minigzipsh$(EXE) \
366372
example64$(EXE) minigzip64$(EXE) \

src/native/external/zlib/README

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
ZLIB DATA COMPRESSION LIBRARY
22

3-
zlib 1.2.13 is a general purpose data compression library. All the code is
3+
zlib 1.3.1 is a general purpose data compression library. All the code is
44
thread safe. The data format used by the zlib library is described by RFCs
55
(Request for Comments) 1950 to 1952 in the files
66
http://tools.ietf.org/html/rfc1950 (zlib format), rfc1951 (deflate format) and
@@ -29,18 +29,17 @@ PLEASE read the zlib FAQ http://zlib.net/zlib_faq.html before asking for help.
2929

3030
Mark Nelson <[email protected]> wrote an article about zlib for the Jan. 1997
3131
issue of Dr. Dobb's Journal; a copy of the article is available at
32-
http://marknelson.us/1997/01/01/zlib-engine/ .
32+
https://marknelson.us/posts/1997/01/01/zlib-engine.html .
3333

34-
The changes made in version 1.2.13 are documented in the file ChangeLog.
34+
The changes made in version 1.3.1 are documented in the file ChangeLog.
3535

3636
Unsupported third party contributions are provided in directory contrib/ .
3737

38-
zlib is available in Java using the java.util.zip package, documented at
39-
http://java.sun.com/developer/technicalArticles/Programming/compression/ .
38+
zlib is available in Java using the java.util.zip package. Follow the API
39+
Documentation link at: https://docs.oracle.com/search/?q=java.util.zip .
4040

41-
A Perl interface to zlib written by Paul Marquess <[email protected]> is available
42-
at CPAN (Comprehensive Perl Archive Network) sites, including
43-
http://search.cpan.org/~pmqs/IO-Compress-Zlib/ .
41+
A Perl interface to zlib and bzip2 written by Paul Marquess <[email protected]>
42+
can be found at https://github.com/pmqs/IO-Compress .
4443

4544
A Python interface to zlib written by A.M. Kuchling <[email protected]> is
4645
available in Python 1.5 and later versions, see
@@ -64,7 +63,7 @@ Notes for some targets:
6463
- zlib doesn't work with gcc 2.6.3 on a DEC 3000/300LX under OSF/1 2.1 it works
6564
when compiled with cc.
6665

67-
- On Digital Unix 4.0D (formely OSF/1) on AlphaServer, the cc option -std1 is
66+
- On Digital Unix 4.0D (formerly OSF/1) on AlphaServer, the cc option -std1 is
6867
necessary to get gzprintf working correctly. This is done by configure.
6968

7069
- zlib doesn't work on HP-UX 9.05 with some versions of /bin/cc. It works with
@@ -84,7 +83,7 @@ Acknowledgments:
8483

8584
Copyright notice:
8685

87-
(C) 1995-2022 Jean-loup Gailly and Mark Adler
86+
(C) 1995-2024 Jean-loup Gailly and Mark Adler
8887

8988
This software is provided 'as-is', without any express or implied
9089
warranty. In no event will the authors be held liable for any damages

0 commit comments

Comments
 (0)