Skip to content

Commit 6e6c7f1

Browse files
deps: update zlib to 1.3.1-7eda07b
1 parent 6aa465c commit 6e6c7f1

File tree

9 files changed

+102
-32
lines changed

9 files changed

+102
-32
lines changed

deps/zlib/contrib/minizip/README.chromium

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,3 +40,6 @@ Local Modifications:
4040
large CRX files).
4141
0018-support-prefixed-zip64.patch
4242

43+
- Added stricter parsing for zip64 candidates to avoid an issue where a zip64
44+
could be embedded in a non-zip64 zip.
45+
0019-fix-zip64-in-zip.patch

deps/zlib/contrib/minizip/unzip.c

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -444,12 +444,28 @@ local ZPOS64_T unz64local_SearchCentralDir64(const zlib_filefunc64_32_def* pzlib
444444
if (ZREAD64(*pzlib_filefunc_def,filestream,buf,uReadSize)!=uReadSize)
445445
break;
446446

447-
for (i=(int)uReadSize-3; (i--)>0;)
447+
/* Search for the non-zip64 EoCDR and confirm zip64 EoCDL is 20 bytes
448+
earlier. This avoids false positives if the file is a non-zip64 zip
449+
but contains an uncompressed zip64 near its end. Note: zip64 EoCDL is
450+
20 bytes long. */
451+
for (i=(int)uReadSize-3; (i--)>20;)
452+
// End of central directory record signature (PK\5\6)
448453
if (((*(buf+i))==0x50) && ((*(buf+i+1))==0x4b) &&
449-
((*(buf+i+2))==0x06) && ((*(buf+i+3))==0x07))
454+
((*(buf+i+2))==0x05) && ((*(buf+i+3))==0x06))
450455
{
451-
uPosFound = uReadPos+(unsigned)i;
452-
break;
456+
// Zip64 end of central directory locator signature (PK\6\7)
457+
if (((*(buf+i-20))==0x50) && ((*(buf+i+1-20))==0x4b) &&
458+
((*(buf+i+2-20))==0x06) && ((*(buf+i+3-20))==0x07))
459+
{
460+
uPosFound = uReadPos+(unsigned)i-20;
461+
break;
462+
}
463+
else
464+
{
465+
/* This is a non-zip64 zip; abandon the search. */
466+
free(buf);
467+
return CENTRALDIRINVALID;
468+
}
453469
}
454470

455471
if (uPosFound!=CENTRALDIRINVALID)

deps/zlib/google/zip_reader.cc

Lines changed: 17 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,14 @@
55
#include "third_party/zlib/google/zip_reader.h"
66

77
#include <algorithm>
8+
#include <cstdint>
89
#include <string_view>
910
#include <utility>
1011

1112
#include "base/check.h"
13+
#include "base/containers/span.h"
1214
#include "base/containers/heap_array.h"
15+
#include "base/strings/string_view_util.h"
1316
#include "base/files/file.h"
1417
#include "base/files/file_util.h"
1518
#include "base/functional/bind.h"
@@ -86,8 +89,8 @@ class StringWriterDelegate : public WriterDelegate {
8689
explicit StringWriterDelegate(std::string* output) : output_(output) {}
8790

8891
// WriterDelegate methods:
89-
bool WriteBytes(const char* data, int num_bytes) override {
90-
output_->append(data, num_bytes);
92+
bool WriteBytes(base::span<const uint8_t> data) override {
93+
*output_ += base::as_string_view(data);
9194
return true;
9295
}
9396

@@ -485,8 +488,10 @@ bool ZipReader::ExtractCurrentEntry(WriterDelegate* delegate,
485488

486489
uint64_t num_bytes_to_write = std::min<uint64_t>(
487490
remaining_capacity, base::checked_cast<uint64_t>(num_bytes_read));
488-
if (!delegate->WriteBytes(buf, num_bytes_to_write))
491+
if (!delegate->WriteBytes(base::as_byte_span(buf).first(
492+
base::checked_cast<size_t>(num_bytes_to_write)))) {
489493
break;
494+
}
490495

491496
if (remaining_capacity == base::checked_cast<uint64_t>(num_bytes_read)) {
492497
// Ensures function returns true if the entire file has been read.
@@ -679,7 +684,9 @@ void ZipReader::ExtractChunk(base::File output_file,
679684
return;
680685
}
681686

682-
if (num_bytes_read != output_file.Write(offset, buffer, num_bytes_read)) {
687+
if (!output_file.WriteAndCheck(
688+
offset, base::as_byte_span(buffer).first(
689+
static_cast<size_t>(num_bytes_read)))) {
683690
LOG(ERROR) << "Cannot write " << num_bytes_read
684691
<< " bytes to file at offset " << offset;
685692
std::move(failure_callback).Run();
@@ -734,11 +741,12 @@ bool FileWriterDelegate::PrepareOutput() {
734741
return true;
735742
}
736743

737-
bool FileWriterDelegate::WriteBytes(const char* data, int num_bytes) {
738-
int bytes_written = file_->WriteAtCurrentPos(data, num_bytes);
739-
if (bytes_written > 0)
740-
file_length_ += bytes_written;
741-
return bytes_written == num_bytes;
744+
bool FileWriterDelegate::WriteBytes(base::span<const uint8_t> data) {
745+
const std::optional<size_t> bytes_written = file_->WriteAtCurrentPos(data);
746+
if (bytes_written > 0) {
747+
file_length_ += *bytes_written;
748+
}
749+
return bytes_written == data.size();
742750
}
743751

744752
void FileWriterDelegate::SetTimeModified(const base::Time& time) {

deps/zlib/google/zip_reader.h

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
#include <string>
1313
#include <string_view>
1414

15+
#include "base/containers/span.h"
1516
#include "base/files/file.h"
1617
#include "base/files/file_path.h"
1718
#include "base/functional/callback.h"
@@ -39,7 +40,7 @@ class WriterDelegate {
3940

4041
// Invoked to write the next chunk of data. Return false on failure to cancel
4142
// extraction.
42-
virtual bool WriteBytes(const char* data, int num_bytes) { return true; }
43+
virtual bool WriteBytes(base::span<const uint8_t> data) { return true; }
4344

4445
// Sets the last-modified time of the data.
4546
virtual void SetTimeModified(const base::Time& time) {}
@@ -377,9 +378,9 @@ class FileWriterDelegate : public WriterDelegate {
377378
// Returns true if the file handle passed to the constructor is valid.
378379
bool PrepareOutput() override;
379380

380-
// Writes |num_bytes| bytes of |data| to the file, returning false on error or
381-
// if not all bytes could be written.
382-
bool WriteBytes(const char* data, int num_bytes) override;
381+
// Writes |data| to the file, returning false on error or if not all bytes
382+
// could be written.
383+
bool WriteBytes(base::span<const uint8_t> data) override;
383384

384385
// Sets the last-modified time of the data.
385386
void SetTimeModified(const base::Time& time) override;

deps/zlib/google/zip_reader_unittest.cc

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ class MockUnzipListener final {
119119
class MockWriterDelegate : public zip::WriterDelegate {
120120
public:
121121
MOCK_METHOD0(PrepareOutput, bool());
122-
MOCK_METHOD2(WriteBytes, bool(const char*, int));
122+
MOCK_METHOD1(WriteBytes, bool(base::span<const uint8_t>));
123123
MOCK_METHOD1(SetTimeModified, void(const base::Time&));
124124
MOCK_METHOD1(SetPosixFilePermissions, void(int));
125125
MOCK_METHOD0(OnError, void());
@@ -896,7 +896,7 @@ TEST_F(ZipReaderTest, ExtractCurrentEntryWriteBytesFailure) {
896896
testing::StrictMock<MockWriterDelegate> mock_writer;
897897

898898
EXPECT_CALL(mock_writer, PrepareOutput()).WillOnce(Return(true));
899-
EXPECT_CALL(mock_writer, WriteBytes(_, _)).WillOnce(Return(false));
899+
EXPECT_CALL(mock_writer, WriteBytes).WillOnce(Return(false));
900900
EXPECT_CALL(mock_writer, OnError());
901901

902902
base::FilePath target_path(FILE_PATH_LITERAL("foo/bar/quux.txt"));
@@ -912,7 +912,7 @@ TEST_F(ZipReaderTest, ExtractCurrentEntrySuccess) {
912912
testing::StrictMock<MockWriterDelegate> mock_writer;
913913

914914
EXPECT_CALL(mock_writer, PrepareOutput()).WillOnce(Return(true));
915-
EXPECT_CALL(mock_writer, WriteBytes(_, _)).WillRepeatedly(Return(true));
915+
EXPECT_CALL(mock_writer, WriteBytes).WillRepeatedly(Return(true));
916916
EXPECT_CALL(mock_writer, SetPosixFilePermissions(_));
917917
EXPECT_CALL(mock_writer, SetTimeModified(_));
918918

@@ -1002,7 +1002,7 @@ TEST_F(FileWriterDelegateTest, WriteToEnd) {
10021002
FileWriterDelegate writer(&file_);
10031003
EXPECT_EQ(0, writer.file_length());
10041004
ASSERT_TRUE(writer.PrepareOutput());
1005-
ASSERT_TRUE(writer.WriteBytes(payload.data(), payload.size()));
1005+
ASSERT_TRUE(writer.WriteBytes(base::as_byte_span(payload)));
10061006
EXPECT_EQ(payload.size(), writer.file_length());
10071007
}
10081008

@@ -1016,7 +1016,7 @@ TEST_F(FileWriterDelegateTest, EmptyOnError) {
10161016
FileWriterDelegate writer(&file_);
10171017
EXPECT_EQ(0, writer.file_length());
10181018
ASSERT_TRUE(writer.PrepareOutput());
1019-
ASSERT_TRUE(writer.WriteBytes(payload.data(), payload.size()));
1019+
ASSERT_TRUE(writer.WriteBytes(base::as_byte_span(payload)));
10201020
EXPECT_EQ(payload.size(), writer.file_length());
10211021
EXPECT_EQ(payload.size(), file_.GetLength());
10221022
writer.OnError();

deps/zlib/google/zip_unittest.cc

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
#include <unordered_set>
1616
#include <vector>
1717

18+
#include "base/containers/span.h"
1819
#include "base/files/file.h"
1920
#include "base/files/file_enumerator.h"
2021
#include "base/files/file_path.h"
@@ -81,8 +82,8 @@ class ProgressWriterDelegate : public zip::WriterDelegate {
8182
CHECK_GT(expected_size_, 0);
8283
}
8384

84-
bool WriteBytes(const char* data, int num_bytes) override {
85-
received_bytes_ += num_bytes;
85+
bool WriteBytes(base::span<const uint8_t> data) override {
86+
received_bytes_ += data.size();
8687
LogProgressIfNecessary();
8788
return true;
8889
}

deps/zlib/google/zip_writer.cc

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,10 @@
77
#include <algorithm>
88
#include <tuple>
99

10+
#include "base/containers/span.h"
1011
#include "base/files/file.h"
1112
#include "base/logging.h"
13+
#include "base/numerics/safe_conversions.h"
1214
#include "base/strings/strcat.h"
1315
#include "base/strings/string_util.h"
1416
#include "third_party/zlib/google/redact.h"
@@ -34,27 +36,29 @@ bool ZipWriter::ShouldContinue() {
3436
}
3537

3638
bool ZipWriter::AddFileContent(const base::FilePath& path, base::File file) {
37-
char buf[zip::internal::kZipBufSize];
39+
uint8_t buf[zip::internal::kZipBufSize];
3840

3941
while (ShouldContinue()) {
40-
const int num_bytes =
41-
file.ReadAtCurrentPos(buf, zip::internal::kZipBufSize);
42+
const std::optional<size_t> num_bytes = file.ReadAtCurrentPos(buf);
4243

43-
if (num_bytes < 0) {
44+
if (!num_bytes) {
4445
PLOG(ERROR) << "Cannot read file " << Redact(path);
4546
return false;
4647
}
4748

48-
if (num_bytes == 0)
49+
if (*num_bytes == 0) {
4950
return true;
51+
}
5052

51-
if (zipWriteInFileInZip(zip_file_, buf, num_bytes) != ZIP_OK) {
53+
if (zipWriteInFileInZip(zip_file_, buf,
54+
base::checked_cast<unsigned int>(*num_bytes)) !=
55+
ZIP_OK) {
5256
PLOG(ERROR) << "Cannot write data from file " << Redact(path)
5357
<< " to ZIP";
5458
return false;
5559
}
5660

57-
progress_.bytes += num_bytes;
61+
progress_.bytes += *num_bytes;
5862
}
5963

6064
return false;
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
diff --git a/third_party/zlib/contrib/minizip/unzip.c b/third_party/zlib/contrib/minizip/unzip.c
2+
index b77b787ccc0db..78663ec2d53a8 100644
3+
--- a/third_party/zlib/contrib/minizip/unzip.c
4+
+++ b/third_party/zlib/contrib/minizip/unzip.c
5+
@@ -444,12 +444,28 @@ local ZPOS64_T unz64local_SearchCentralDir64(const zlib_filefunc64_32_def* pzlib
6+
if (ZREAD64(*pzlib_filefunc_def,filestream,buf,uReadSize)!=uReadSize)
7+
break;
8+
9+
- for (i=(int)uReadSize-3; (i--)>0;)
10+
+ /* Search for the non-zip64 EoCDR and confirm zip64 EoCDL is 20 bytes
11+
+ earlier. This avoids false positives if the file is a non-zip64 zip
12+
+ but contains an uncompressed zip64 near its end. Note: zip64 EoCDL is
13+
+ 20 bytes long. */
14+
+ for (i=(int)uReadSize-3; (i--)>20;)
15+
+ // End of central directory record signature (PK\5\6)
16+
if (((*(buf+i))==0x50) && ((*(buf+i+1))==0x4b) &&
17+
- ((*(buf+i+2))==0x06) && ((*(buf+i+3))==0x07))
18+
+ ((*(buf+i+2))==0x05) && ((*(buf+i+3))==0x06))
19+
{
20+
- uPosFound = uReadPos+(unsigned)i;
21+
- break;
22+
+ // Zip64 end of central directory locator signature (PK\6\7)
23+
+ if (((*(buf+i-20))==0x50) && ((*(buf+i+1-20))==0x4b) &&
24+
+ ((*(buf+i+2-20))==0x06) && ((*(buf+i+3-20))==0x07))
25+
+ {
26+
+ uPosFound = uReadPos+(unsigned)i-20;
27+
+ break;
28+
+ }
29+
+ else
30+
+ {
31+
+ /* This is a non-zip64 zip; abandon the search. */
32+
+ free(buf);
33+
+ return CENTRALDIRINVALID;
34+
+ }
35+
}
36+
37+
if (uPosFound!=CENTRALDIRINVALID)

src/zlib_version.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,5 @@
22
// Refer to tools/dep_updaters/update-zlib.sh
33
#ifndef SRC_ZLIB_VERSION_H_
44
#define SRC_ZLIB_VERSION_H_
5-
#define ZLIB_VERSION "1.3.1-e00f703"
5+
#define ZLIB_VERSION "1.3.1-7eda07b"
66
#endif // SRC_ZLIB_VERSION_H_

0 commit comments

Comments
 (0)