| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -3,6 +3,7 @@ | |||
| 3 | 3 | # found in the LICENSE file. | |
| 4 | 4 | ||
| 5 | 5 | import("//build/config/compiler/compiler.gni") | |
| 6 | + import("//build/config/dcheck_always_on.gni") | ||
| 6 | 7 | ||
| 7 | 8 | declare_args() { | |
| 8 | 9 | # Expose zlib's symbols, used by Node.js to provide zlib APIs for its native | |
@@ -33,7 +34,7 @@ config("zlib_internal_config") { | |||
| 33 | 34 | # Build code using -O3, see: crbug.com/1084371. | |
| 34 | 35 | configs = [ "//build/config/compiler:optimize_speed" ] | |
| 35 | 36 | } | |
| 36 | - if (is_debug || use_fuzzing_engine) { | ||
| 37 | + if (is_debug || dcheck_always_on || use_fuzzing_engine) { | ||
| 37 | 38 | # Enable zlib's asserts in debug and fuzzer builds. | |
| 38 | 39 | defines += [ "ZLIB_DEBUG" ] | |
| 39 | 40 | } | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -1025,6 +1025,61 @@ TEST(ZlibTest, DeflateZFixedCorruption) { | |||
| 1025 | 1025 | 0); | |
| 1026 | 1026 | } | |
| 1027 | 1027 | ||
| 1028 | + TEST(ZlibTest, DeflateCopy) { | ||
| 1029 | + // Check that deflateCopy() works. | ||
| 1030 | + | ||
| 1031 | + z_stream stream1; | ||
| 1032 | + stream1.zalloc = Z_NULL; | ||
| 1033 | + stream1.zfree = Z_NULL; | ||
| 1034 | + int ret = | ||
| 1035 | + deflateInit(&stream1, Z_DEFAULT_COMPRESSION); | ||
| 1036 | + ASSERT_EQ(ret, Z_OK); | ||
| 1037 | + std::vector<uint8_t> compressed( | ||
| 1038 | + deflateBound(&stream1, strlen(zFixedCorruptionData))); | ||
| 1039 | + stream1.next_out = compressed.data(); | ||
| 1040 | + stream1.avail_out = compressed.size(); | ||
| 1041 | + | ||
| 1042 | + // Compress the first 1000 bytes. | ||
| 1043 | + stream1.next_in = (uint8_t*)zFixedCorruptionData; | ||
| 1044 | + stream1.avail_in = 1000; | ||
| 1045 | + ret = deflate(&stream1, Z_NO_FLUSH); | ||
| 1046 | + ASSERT_EQ(ret, Z_OK); | ||
| 1047 | + | ||
| 1048 | + // Copy the stream state. | ||
| 1049 | + z_stream stream2; | ||
| 1050 | + ret = deflateCopy(&stream2, &stream1); | ||
| 1051 | + ASSERT_EQ(ret, Z_OK); | ||
| 1052 | + deflateEnd(&stream1); | ||
| 1053 | + | ||
| 1054 | + // Compress the remaining bytes. | ||
| 1055 | + stream2.next_in = (uint8_t*)zFixedCorruptionData + (1000 - stream2.avail_in); | ||
| 1056 | + stream2.avail_in = strlen(zFixedCorruptionData) - (1000 - stream2.avail_in); | ||
| 1057 | + ret = deflate(&stream2, Z_FINISH); | ||
| 1058 | + ASSERT_EQ(ret, Z_STREAM_END); | ||
| 1059 | + size_t compressed_sz = compressed.size() - stream2.avail_out; | ||
| 1060 | + deflateEnd(&stream2); | ||
| 1061 | + | ||
| 1062 | + // Check that decompression is successful. | ||
| 1063 | + std::vector<uint8_t> decompressed(strlen(zFixedCorruptionData)); | ||
| 1064 | + z_stream stream; | ||
| 1065 | + stream.zalloc = Z_NULL; | ||
| 1066 | + stream.zfree = Z_NULL; | ||
| 1067 | + ret = inflateInit(&stream); | ||
| 1068 | + ASSERT_EQ(ret, Z_OK); | ||
| 1069 | + stream.next_in = compressed.data(); | ||
| 1070 | + stream.avail_in = compressed_sz; | ||
| 1071 | + stream.next_out = decompressed.data(); | ||
| 1072 | + stream.avail_out = decompressed.size(); | ||
| 1073 | + ret = inflate(&stream, Z_FINISH); | ||
| 1074 | + ASSERT_EQ(ret, Z_STREAM_END); | ||
| 1075 | + inflateEnd(&stream); | ||
| 1076 | + | ||
| 1077 | + EXPECT_EQ(decompressed.size(), strlen(zFixedCorruptionData)); | ||
| 1078 | + EXPECT_EQ( | ||
| 1079 | + memcmp(zFixedCorruptionData, decompressed.data(), decompressed.size()), | ||
| 1080 | + 0); | ||
| 1081 | + } | ||
| 1082 | + | ||
| 1028 | 1083 | // TODO(gustavoa): make these tests run standalone. | |
| 1029 | 1084 | #ifndef CMAKE_STANDALONE_UNITTESTS | |
| 1030 | 1085 | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -1345,7 +1345,11 @@ int ZEXPORT deflateCopy(z_streamp dest, z_streamp source) { | |||
| 1345 | 1345 | ds->window = (Bytef *) ZALLOC(dest, ds->w_size, 2*sizeof(Byte)); | |
| 1346 | 1346 | ds->prev = (Posf *) ZALLOC(dest, ds->w_size, sizeof(Pos)); | |
| 1347 | 1347 | ds->head = (Posf *) ZALLOC(dest, ds->hash_size, sizeof(Pos)); | |
| 1348 | + #ifdef LIT_MEM | ||
| 1349 | + ds->pending_buf = (uchf *) ZALLOC(dest, ds->lit_bufsize, 5); | ||
| 1350 | + #else | ||
| 1348 | 1351 | ds->pending_buf = (uchf *) ZALLOC(dest, ds->lit_bufsize, 4); | |
| 1352 | + #endif | ||
| 1349 | 1353 | ||
| 1350 | 1354 | if (ds->window == Z_NULL || ds->prev == Z_NULL || ds->head == Z_NULL || | |
| 1351 | 1355 | ds->pending_buf == Z_NULL) { | |
@@ -1356,7 +1360,11 @@ int ZEXPORT deflateCopy(z_streamp dest, z_streamp source) { | |||
| 1356 | 1360 | zmemcpy(ds->window, ss->window, ds->w_size * 2 * sizeof(Byte)); | |
| 1357 | 1361 | zmemcpy((voidpf)ds->prev, (voidpf)ss->prev, ds->w_size * sizeof(Pos)); | |
| 1358 | 1362 | zmemcpy((voidpf)ds->head, (voidpf)ss->head, ds->hash_size * sizeof(Pos)); | |
| 1363 | + #ifdef LIT_MEM | ||
| 1364 | + zmemcpy(ds->pending_buf, ss->pending_buf, (uInt)ds->lit_bufsize * 5); | ||
| 1365 | + #else | ||
| 1359 | 1366 | zmemcpy(ds->pending_buf, ss->pending_buf, (uInt)ds->pending_buf_size); | |
| 1367 | + #endif | ||
| 1360 | 1368 | ||
| 1361 | 1369 | ds->pending_out = ds->pending_buf + (ss->pending_out - ss->pending_buf); | |
| 1362 | 1370 | #ifdef LIT_MEM | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -25,7 +25,7 @@ | |||
| 25 | 25 | ||
| 26 | 26 | /* define LIT_MEM to slightly increase the speed of deflate (order 1% to 2%) at | |
| 27 | 27 | the cost of a larger memory footprint */ | |
| 28 | - /* #define LIT_MEM */ | ||
| 28 | + #define LIT_MEM | ||
| 29 | 29 | ||
| 30 | 30 | /* =========================================================================== | |
| 31 | 31 | * Internal compression state. | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -4,7 +4,6 @@ | |||
| 4 | 4 | ||
| 5 | 5 | #include "third_party/zlib/google/compression_utils.h" | |
| 6 | 6 | ||
| 7 | - #include "base/bit_cast.h" | ||
| 8 | 7 | #include "base/check_op.h" | |
| 9 | 8 | #include "base/process/memory.h" | |
| 10 | 9 | #include "base/sys_byteorder.h" | |
@@ -24,8 +23,8 @@ bool GzipCompress(base::span<const char> input, | |||
| 24 | 23 | // uLongf can be larger than size_t. | |
| 25 | 24 | uLongf compressed_size_long = static_cast<uLongf>(output_buffer_size); | |
| 26 | 25 | if (zlib_internal::GzipCompressHelper( | |
| 27 | - base::bit_cast<Bytef*>(output_buffer), &compressed_size_long, | ||
| 28 | - base::bit_cast<const Bytef*>(input.data()), | ||
| 26 | + reinterpret_cast<Bytef*>(output_buffer), &compressed_size_long, | ||
| 27 | + reinterpret_cast<const Bytef*>(input.data()), | ||
| 29 | 28 | static_cast<uLongf>(input.size()), malloc_fn, free_fn) != Z_OK) { | |
| 30 | 29 | return false; | |
| 31 | 30 | } | |
@@ -55,7 +54,7 @@ bool GzipCompress(base::span<const uint8_t> input, std::string* output) { | |||
| 55 | 54 | ||
| 56 | 55 | if (zlib_internal::GzipCompressHelper( | |
| 57 | 56 | compressed_data, &compressed_data_size, | |
| 58 | - base::bit_cast<const Bytef*>(input.data()), input_size, nullptr, | ||
| 57 | + reinterpret_cast<const Bytef*>(input.data()), input_size, nullptr, | ||
| 59 | 58 | nullptr) != Z_OK) { | |
| 60 | 59 | free(compressed_data); | |
| 61 | 60 | return false; | |
@@ -82,8 +81,8 @@ bool GzipUncompress(const std::string& input, std::string* output) { | |||
| 82 | 81 | ||
| 83 | 82 | uncompressed_output.resize(uncompressed_size); | |
| 84 | 83 | if (zlib_internal::GzipUncompressHelper( | |
| 85 | - base::bit_cast<Bytef*>(uncompressed_output.data()), | ||
| 86 | - &uncompressed_size, base::bit_cast<const Bytef*>(input.data()), | ||
| 84 | + reinterpret_cast<Bytef*>(uncompressed_output.data()), | ||
| 85 | + &uncompressed_size, reinterpret_cast<const Bytef*>(input.data()), | ||
| 87 | 86 | static_cast<uLongf>(input.length())) == Z_OK) { | |
| 88 | 87 | output->swap(uncompressed_output); | |
| 89 | 88 | return true; | |
@@ -102,8 +101,8 @@ bool GzipUncompress(base::span<const uint8_t> input, | |||
| 102 | 101 | if (uncompressed_size > output.size()) | |
| 103 | 102 | return false; | |
| 104 | 103 | return zlib_internal::GzipUncompressHelper( | |
| 105 | - base::bit_cast<Bytef*>(output.data()), &uncompressed_size, | ||
| 106 | - base::bit_cast<const Bytef*>(input.data()), | ||
| 104 | + reinterpret_cast<Bytef*>(const_cast<uint8_t*>(output.data())), | ||
| 105 | + &uncompressed_size, reinterpret_cast<const Bytef*>(input.data()), | ||
| 107 | 106 | static_cast<uLongf>(input.size())) == Z_OK; | |
| 108 | 107 | } | |
| 109 | 108 | ||
@@ -117,8 +116,8 @@ bool GzipUncompress(base::span<const uint8_t> input, std::string* output) { | |||
| 117 | 116 | uLongf uncompressed_size = GetUncompressedSize(input); | |
| 118 | 117 | output->resize(uncompressed_size); | |
| 119 | 118 | return zlib_internal::GzipUncompressHelper( | |
| 120 | - base::bit_cast<Bytef*>(output->data()), &uncompressed_size, | ||
| 121 | - base::bit_cast<const Bytef*>(input.data()), | ||
| 119 | + reinterpret_cast<Bytef*>(output->data()), &uncompressed_size, | ||
| 120 | + reinterpret_cast<const Bytef*>(input.data()), | ||
| 122 | 121 | static_cast<uLongf>(input.size())) == Z_OK; | |
| 123 | 122 | } | |
| 124 | 123 | ||
@@ -128,7 +127,8 @@ uint32_t GetUncompressedSize(base::span<const char> compressed_data) { | |||
| 128 | 127 | ||
| 129 | 128 | uint32_t GetUncompressedSize(base::span<const uint8_t> compressed_data) { | |
| 130 | 129 | return zlib_internal::GetGzipUncompressedSize( | |
| 131 | - base::bit_cast<Bytef*>(compressed_data.data()), compressed_data.size()); | ||
| 130 | + reinterpret_cast<const Bytef*>(compressed_data.data()), | ||
| 131 | + compressed_data.size()); | ||
| 132 | 132 | } | |
| 133 | 133 | ||
| 134 | 134 | } // namespace compression | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -938,7 +938,8 @@ local void compress_block(deflate_state *s, const ct_data *ltree, | |||
| 938 | 938 | ||
| 939 | 939 | /* Check for no overlay of pending_buf on needed symbols */ | |
| 940 | 940 | #ifdef LIT_MEM | |
| 941 | - Assert(s->pending < (s->lit_bufsize << 1) + sx, "pendingBuf overflow"); | ||
| 941 | + Assert(s->pending < (s->lit_bufsize << 1) + (sx << 1), | ||
| 942 | + "pendingBuf overflow"); | ||
| 942 | 943 | #else | |
| 943 | 944 | Assert(s->pending < s->lit_bufsize + sx, "pendingBuf overflow"); | |
| 944 | 945 | #endif | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -2,5 +2,5 @@ | |||
| 2 | 2 | // Refer to tools/dep_updaters/update-zlib.sh | |
| 3 | 3 | #ifndef SRC_ZLIB_VERSION_H_ | |
| 4 | 4 | #define SRC_ZLIB_VERSION_H_ | |
| 5 | - #define ZLIB_VERSION "1.3.0.1-motley-dd5fc13" | ||
| 5 | + #define ZLIB_VERSION "1.3.0.1-motley-40e35a7" | ||
| 6 | 6 | #endif // SRC_ZLIB_VERSION_H_ | |
| Back | FazBrowse Home | New Git URL |
0 commit comments