Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 17 additions & 9 deletions deps/zlib/google/zip_reader.cc
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,14 @@
#include "third_party/zlib/google/zip_reader.h"

#include <algorithm>
#include <cstdint>
#include <string_view>
#include <utility>

#include "base/check.h"
#include "base/containers/span.h"
#include "base/containers/heap_array.h"
#include "base/strings/string_view_util.h"
#include "base/files/file.h"
#include "base/files/file_util.h"
#include "base/functional/bind.h"
Expand Down Expand Up @@ -86,8 +89,8 @@ class StringWriterDelegate : public WriterDelegate {
explicit StringWriterDelegate(std::string* output) : output_(output) {}

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

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

uint64_t num_bytes_to_write = std::min<uint64_t>(
remaining_capacity, base::checked_cast<uint64_t>(num_bytes_read));
if (!delegate->WriteBytes(buf, num_bytes_to_write))
if (!delegate->WriteBytes(base::as_byte_span(buf).first(
base::checked_cast<size_t>(num_bytes_to_write)))) {
break;
}

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

if (num_bytes_read != output_file.Write(offset, buffer, num_bytes_read)) {
if (!output_file.WriteAndCheck(
offset, base::as_byte_span(buffer).first(
static_cast<size_t>(num_bytes_read)))) {
LOG(ERROR) << "Cannot write " << num_bytes_read
<< " bytes to file at offset " << offset;
std::move(failure_callback).Run();
Expand Down Expand Up @@ -734,11 +741,12 @@ bool FileWriterDelegate::PrepareOutput() {
return true;
}

bool FileWriterDelegate::WriteBytes(const char* data, int num_bytes) {
int bytes_written = file_->WriteAtCurrentPos(data, num_bytes);
if (bytes_written > 0)
file_length_ += bytes_written;
return bytes_written == num_bytes;
bool FileWriterDelegate::WriteBytes(base::span<const uint8_t> data) {
const std::optional<size_t> bytes_written = file_->WriteAtCurrentPos(data);
if (bytes_written > 0) {
file_length_ += *bytes_written;
}
return bytes_written == data.size();
}

void FileWriterDelegate::SetTimeModified(const base::Time& time) {
Expand Down
9 changes: 5 additions & 4 deletions deps/zlib/google/zip_reader.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
#include <string>
#include <string_view>

#include "base/containers/span.h"
#include "base/files/file.h"
#include "base/files/file_path.h"
#include "base/functional/callback.h"
Expand Down Expand Up @@ -39,7 +40,7 @@ class WriterDelegate {

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

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

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

// Sets the last-modified time of the data.
void SetTimeModified(const base::Time& time) override;
Expand Down
10 changes: 5 additions & 5 deletions deps/zlib/google/zip_reader_unittest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ class MockUnzipListener final {
class MockWriterDelegate : public zip::WriterDelegate {
public:
MOCK_METHOD0(PrepareOutput, bool());
MOCK_METHOD2(WriteBytes, bool(const char*, int));
MOCK_METHOD1(WriteBytes, bool(base::span<const uint8_t>));
MOCK_METHOD1(SetTimeModified, void(const base::Time&));
MOCK_METHOD1(SetPosixFilePermissions, void(int));
MOCK_METHOD0(OnError, void());
Expand Down Expand Up @@ -896,7 +896,7 @@ TEST_F(ZipReaderTest, ExtractCurrentEntryWriteBytesFailure) {
testing::StrictMock<MockWriterDelegate> mock_writer;

EXPECT_CALL(mock_writer, PrepareOutput()).WillOnce(Return(true));
EXPECT_CALL(mock_writer, WriteBytes(_, _)).WillOnce(Return(false));
EXPECT_CALL(mock_writer, WriteBytes).WillOnce(Return(false));
EXPECT_CALL(mock_writer, OnError());

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

EXPECT_CALL(mock_writer, PrepareOutput()).WillOnce(Return(true));
EXPECT_CALL(mock_writer, WriteBytes(_, _)).WillRepeatedly(Return(true));
EXPECT_CALL(mock_writer, WriteBytes).WillRepeatedly(Return(true));
EXPECT_CALL(mock_writer, SetPosixFilePermissions(_));
EXPECT_CALL(mock_writer, SetTimeModified(_));

Expand Down Expand Up @@ -1002,7 +1002,7 @@ TEST_F(FileWriterDelegateTest, WriteToEnd) {
FileWriterDelegate writer(&file_);
EXPECT_EQ(0, writer.file_length());
ASSERT_TRUE(writer.PrepareOutput());
ASSERT_TRUE(writer.WriteBytes(payload.data(), payload.size()));
ASSERT_TRUE(writer.WriteBytes(base::as_byte_span(payload)));
EXPECT_EQ(payload.size(), writer.file_length());
}

Expand All @@ -1016,7 +1016,7 @@ TEST_F(FileWriterDelegateTest, EmptyOnError) {
FileWriterDelegate writer(&file_);
EXPECT_EQ(0, writer.file_length());
ASSERT_TRUE(writer.PrepareOutput());
ASSERT_TRUE(writer.WriteBytes(payload.data(), payload.size()));
ASSERT_TRUE(writer.WriteBytes(base::as_byte_span(payload)));
EXPECT_EQ(payload.size(), writer.file_length());
EXPECT_EQ(payload.size(), file_.GetLength());
writer.OnError();
Expand Down
5 changes: 3 additions & 2 deletions deps/zlib/google/zip_unittest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
#include <unordered_set>
#include <vector>

#include "base/containers/span.h"
#include "base/files/file.h"
#include "base/files/file_enumerator.h"
#include "base/files/file_path.h"
Expand Down Expand Up @@ -81,8 +82,8 @@ class ProgressWriterDelegate : public zip::WriterDelegate {
CHECK_GT(expected_size_, 0);
}

bool WriteBytes(const char* data, int num_bytes) override {
received_bytes_ += num_bytes;
bool WriteBytes(base::span<const uint8_t> data) override {
received_bytes_ += data.size();
LogProgressIfNecessary();
return true;
}
Expand Down
18 changes: 11 additions & 7 deletions deps/zlib/google/zip_writer.cc
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,10 @@
#include <algorithm>
#include <tuple>

#include "base/containers/span.h"
#include "base/files/file.h"
#include "base/logging.h"
#include "base/numerics/safe_conversions.h"
#include "base/strings/strcat.h"
#include "base/strings/string_util.h"
#include "third_party/zlib/google/redact.h"
Expand All @@ -34,27 +36,29 @@ bool ZipWriter::ShouldContinue() {
}

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

while (ShouldContinue()) {
const int num_bytes =
file.ReadAtCurrentPos(buf, zip::internal::kZipBufSize);
const std::optional<size_t> num_bytes = file.ReadAtCurrentPos(buf);

if (num_bytes < 0) {
if (!num_bytes) {
PLOG(ERROR) << "Cannot read file " << Redact(path);
return false;
}

if (num_bytes == 0)
if (*num_bytes == 0) {
return true;
}

if (zipWriteInFileInZip(zip_file_, buf, num_bytes) != ZIP_OK) {
if (zipWriteInFileInZip(zip_file_, buf,
base::checked_cast<unsigned int>(*num_bytes)) !=
ZIP_OK) {
PLOG(ERROR) << "Cannot write data from file " << Redact(path)
<< " to ZIP";
return false;
}

progress_.bytes += num_bytes;
progress_.bytes += *num_bytes;
}

return false;
Expand Down
2 changes: 1 addition & 1 deletion src/zlib_version.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@
// Refer to tools/dep_updaters/update-zlib.sh
#ifndef SRC_ZLIB_VERSION_H_
#define SRC_ZLIB_VERSION_H_
#define ZLIB_VERSION "1.3.1-e00f703"
#define ZLIB_VERSION "1.3.1-980253c"
#endif // SRC_ZLIB_VERSION_H_
Loading