diff options
author | Treehugger Robot <android-test-infra-autosubmit@system.gserviceaccount.com> | 2024-02-27 04:18:45 +0000 |
---|---|---|
committer | Gerrit Code Review <noreply-gerritcodereview@google.com> | 2024-02-27 04:18:45 +0000 |
commit | 14db8b8c0f2576028ff3e60093b669b747c9206e (patch) | |
tree | 90533f4776266a1e995a6ee7d15015d0c19f19e8 | |
parent | ecca3e0b49796339fb185fd1cb312bbc5537158f (diff) | |
parent | 8f513c9cebd574037e4eb5a8cf195bdbced74bd1 (diff) | |
download | zlib-14db8b8c0f2576028ff3e60093b669b747c9206e.tar.gz |
Merge "Upgrade zlib to 3787595bbbd3a374613713164db935e8331f5825" into main
-rw-r--r-- | CMakeLists.txt | 14 | ||||
-rw-r--r-- | DIR_METADATA | 3 | ||||
-rw-r--r-- | METADATA | 8 | ||||
-rw-r--r-- | contrib/tests/fuzzers/deflate_fuzzer.cc | 73 | ||||
-rw-r--r-- | contrib/tests/utils_unittest.cc | 25 | ||||
-rw-r--r-- | crc_folding.c | 2 | ||||
-rw-r--r-- | patches/0001-simd.patch | 2 | ||||
-rw-r--r-- | zutil.h | 23 |
8 files changed, 97 insertions, 53 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt index 5541985..394d833 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -25,6 +25,7 @@ option(ENABLE_SIMD_OPTIMIZATIONS "Enable all SIMD optimizations" OFF) option(ENABLE_SIMD_AVX512 "Enable SIMD AXV512 optimizations" OFF) option(USE_ZLIB_RABIN_KARP_HASH "Enable bitstream compatibility with canonical zlib" OFF) option(BUILD_UNITTESTS "Enable standalone unit tests build" OFF) +option(BUILD_MINIZIP_BIN "Enable building minzip_bin tool" OFF) if (USE_ZLIB_RABIN_KARP_HASH) add_definitions(-DUSE_ZLIB_RABIN_KARP_ROLLING_HASH) @@ -300,8 +301,11 @@ endif() #============================================================================ # Minigzip tool #============================================================================ -add_executable(minizip_bin contrib/minizip/minizip.c contrib/minizip/ioapi.c -contrib/minizip/ioapi.h contrib/minizip/unzip.c -contrib/minizip/unzip.h contrib/minizip/zip.c contrib/minizip/zip.h -) -target_link_libraries(minizip_bin zlib) +# TODO(cavalcantii): get it working on Windows. +if (BUILD_MINIZIP_BIN) + add_executable(minizip_bin contrib/minizip/minizip.c contrib/minizip/ioapi.c + contrib/minizip/ioapi.h contrib/minizip/unzip.c + contrib/minizip/unzip.h contrib/minizip/zip.c contrib/minizip/zip.h + ) + target_link_libraries(minizip_bin zlib) +endif() diff --git a/DIR_METADATA b/DIR_METADATA index d366dc7..45f7798 100644 --- a/DIR_METADATA +++ b/DIR_METADATA @@ -1,3 +1,6 @@ monorail: { component: "Internals" } +buganizer_public: { + component_id: 1456292 +} @@ -1,5 +1,5 @@ # This project was upgraded with external_updater. -# Usage: tools/external_updater/updater.sh update zlib +# Usage: tools/external_updater/updater.sh update external/zlib # For more info, check https://cs.android.com/android/platform/superproject/+/main:tools/external_updater/README.md name: "zlib" @@ -8,12 +8,12 @@ third_party { license_type: NOTICE last_upgrade_date { year: 2024 - month: 1 - day: 23 + month: 2 + day: 26 } identifier { type: "Git" value: "https://chromium.googlesource.com/chromium/src/third_party/zlib/" - version: "63c0cec0344e6ba70f22bd690187088299baaa94" + version: "3787595bbbd3a374613713164db935e8331f5825" } } diff --git a/contrib/tests/fuzzers/deflate_fuzzer.cc b/contrib/tests/fuzzers/deflate_fuzzer.cc index 64892bc..6f3e45e 100644 --- a/contrib/tests/fuzzers/deflate_fuzzer.cc +++ b/contrib/tests/fuzzers/deflate_fuzzer.cc @@ -23,42 +23,75 @@ extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) { FuzzedDataProvider fdp(data, size); - int level = fdp.PickValueInArray({0, 1, 2, 3, 4, 5, 6, 7, 8, 9}); + int level = fdp.PickValueInArray({-1, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9}); int windowBits = fdp.PickValueInArray({9, 10, 11, 12, 13, 14, 15}); int memLevel = fdp.PickValueInArray({1, 2, 3, 4, 5, 6, 7, 8, 9}); int strategy = fdp.PickValueInArray( {Z_DEFAULT_STRATEGY, Z_FILTERED, Z_HUFFMAN_ONLY, Z_RLE, Z_FIXED}); - std::vector<uint8_t> src = fdp.ConsumeRemainingBytes<uint8_t>(); + + if (fdp.ConsumeBool()) { + // Gzip wrapper. + windowBits += 16; + } else if (fdp.ConsumeBool()) { + // Raw deflate. + windowBits *= -1; + } else { + // Default: zlib wrapper. + } + + std::vector<uint8_t> src; + std::vector<uint8_t> compressed; + static const int kMinChunk = 1; + static const int kMaxChunk = 512 * 1024; z_stream stream; stream.zalloc = Z_NULL; stream.zfree = Z_NULL; - - // Compress the data one byte at a time to exercise the streaming code. int ret = deflateInit2(&stream, level, Z_DEFLATED, windowBits, memLevel, strategy); ASSERT(ret == Z_OK); - size_t deflate_bound = deflateBound(&stream, src.size()); - - std::vector<uint8_t> compressed(src.size() * 2 + 1000); - stream.next_out = compressed.data(); - stream.avail_out = compressed.size(); - for (uint8_t b : src) { - stream.next_in = &b; - stream.avail_in = 1; + // Stream with random-sized input and output buffers. + while (fdp.ConsumeBool()) { + std::vector<uint8_t> src_chunk = fdp.ConsumeBytes<uint8_t>( + fdp.ConsumeIntegralInRange(kMinChunk, kMaxChunk)); + std::vector<uint8_t> out_chunk( + fdp.ConsumeIntegralInRange(kMinChunk, kMaxChunk)); + stream.next_in = src_chunk.data(); + stream.avail_in = src_chunk.size(); + stream.next_out = out_chunk.data(); + stream.avail_out = out_chunk.size(); ret = deflate(&stream, Z_NO_FLUSH); - ASSERT(ret == Z_OK); + ASSERT(ret == Z_OK || ret == Z_BUF_ERROR); + + src.insert(src.end(), src_chunk.begin(), src_chunk.end() - stream.avail_in); + compressed.insert(compressed.end(), out_chunk.begin(), + out_chunk.end() - stream.avail_out); + } + // Finish up. + while (true) { + std::vector<uint8_t> out_chunk( + fdp.ConsumeIntegralInRange(kMinChunk, kMaxChunk)); + stream.next_in = Z_NULL; + stream.avail_in = 0; + stream.next_out = out_chunk.data(); + stream.avail_out = out_chunk.size(); + ret = deflate(&stream, Z_FINISH); + compressed.insert(compressed.end(), out_chunk.begin(), + out_chunk.end() - stream.avail_out); + if (ret == Z_STREAM_END) { + break; + } + ASSERT(ret == Z_OK || Z_BUF_ERROR); } - stream.next_in = Z_NULL; - stream.avail_in = 0; - ret = deflate(&stream, Z_FINISH); - ASSERT(ret == Z_STREAM_END); - compressed.resize(compressed.size() - stream.avail_out); - deflateEnd(&stream); // Check that the bound was correct. - ASSERT(compressed.size() <= deflate_bound); + // size_t deflate_bound = deflateBound(&stream, src.size()); + // TODO(crbug.com/40270738): This does not always hold. + // ASSERT(compressed.size() <= deflate_bound); + + deflateEnd(&stream); + // Verify that the data decompresses correctly. ret = inflateInit2(&stream, windowBits); diff --git a/contrib/tests/utils_unittest.cc b/contrib/tests/utils_unittest.cc index 4a80277..3d6672d 100644 --- a/contrib/tests/utils_unittest.cc +++ b/contrib/tests/utils_unittest.cc @@ -1080,6 +1080,31 @@ TEST(ZlibTest, DeflateCopy) { 0); } +TEST(ZlibTest, GzipStored) { + // Check that deflating uncompressed blocks with a gzip header doesn't write + // out of bounds (crbug.com/325990053). + z_stream stream; + stream.zalloc = Z_NULL; + stream.zfree = Z_NULL; + static const int kGzipWrapper = 16; + int ret = deflateInit2(&stream, Z_NO_COMPRESSION, Z_DEFLATED, + 9 + kGzipWrapper, 9, Z_DEFAULT_STRATEGY); + ASSERT_EQ(ret, Z_OK); + + const std::vector<uint8_t> src(512 * 1024); + stream.next_in = (unsigned char*)src.data(); + stream.avail_in = src.size(); + + std::vector<uint8_t> out(1000); + stream.next_out = (unsigned char*)out.data(); + stream.avail_out = out.size(); + + ret = deflate(&stream, Z_NO_FLUSH); + ASSERT_EQ(ret, Z_OK); + + deflateEnd(&stream); +} + // TODO(gustavoa): make these tests run standalone. #ifndef CMAKE_STANDALONE_UNITTESTS diff --git a/crc_folding.c b/crc_folding.c index 1b4f4e1..1d54ee8 100644 --- a/crc_folding.c +++ b/crc_folding.c @@ -403,7 +403,7 @@ partial: } #endif - _mm_storeu_si128((__m128i *)dst, xmm_crc_part); + zmemcpy(dst, src, len); /* TODO: Possibly generate more efficient code. */ partial_fold(s, len, &xmm_crc0, &xmm_crc1, &xmm_crc2, &xmm_crc3, &xmm_crc_part); done: diff --git a/patches/0001-simd.patch b/patches/0001-simd.patch index 9434ca0..dccf505 100644 --- a/patches/0001-simd.patch +++ b/patches/0001-simd.patch @@ -449,7 +449,7 @@ index 000000000000..48d77744aaf4 + } +#endif + -+ _mm_storeu_si128((__m128i *)dst, xmm_crc_part); ++ zmemcpy(dst, src, len); /* TODO: Possibly generate more efficient code. */ + partial_fold(s, len, &xmm_crc0, &xmm_crc1, &xmm_crc2, &xmm_crc3, + &xmm_crc_part); +done: @@ -152,17 +152,8 @@ extern z_const char * const z_errmsg[10]; /* indexed by 2-zlib_error */ # endif #endif -#if defined(MACOS) || defined(TARGET_OS_MAC) +#if defined(MACOS) # define OS_CODE 7 -# ifndef Z_SOLO -# if defined(__MWERKS__) && __dest_os != __be_os && __dest_os != __win32_os -# include <unix.h> /* for fdopen */ -# else -# ifndef fdopen -# define fdopen(fd,mode) NULL /* No fdopen() */ -# endif -# endif -# endif #endif #ifdef __acorn @@ -185,18 +176,6 @@ extern z_const char * const z_errmsg[10]; /* indexed by 2-zlib_error */ # define OS_CODE 19 #endif -#if defined(_BEOS_) || defined(RISCOS) -# define fdopen(fd,mode) NULL /* No fdopen() */ -#endif - -#if (defined(_MSC_VER) && (_MSC_VER > 600)) && !defined __INTERIX -# if defined(_WIN32_WCE) -# define fdopen(fd,mode) NULL /* No fdopen() */ -# else -# define fdopen(fd,type) _fdopen(fd,type) -# endif -#endif - #if defined(__BORLANDC__) && !defined(MSDOS) #pragma warn -8004 #pragma warn -8008 |