diff --git a/shell/common/asar/archive.cc b/shell/common/asar/archive.cc index 479e8fe891ab..6f2b680394a9 100644 --- a/shell/common/asar/archive.cc +++ b/shell/common/asar/archive.cc @@ -201,22 +201,19 @@ bool Archive::Init() { return false; } - std::vector buf; - int len; + std::vector buf; buf.resize(8); { electron::ScopedAllowBlockingForElectron allow_blocking; - len = file_.ReadAtCurrentPos(buf.data(), buf.size()); - } - if (len != static_cast(buf.size())) { - PLOG(ERROR) << "Failed to read header size from " << path_.value(); - return false; + if (!file_.ReadAtCurrentPosAndCheck(buf)) { + PLOG(ERROR) << "Failed to read header size from " << path_.value(); + return false; + } } uint32_t size; - if (!base::PickleIterator(base::Pickle::WithData(base::as_byte_span(buf))) - .ReadUInt32(&size)) { + if (!base::PickleIterator(base::Pickle::WithData(buf)).ReadUInt32(&size)) { LOG(ERROR) << "Failed to parse header size from " << path_.value(); return false; } @@ -224,16 +221,14 @@ bool Archive::Init() { buf.resize(size); { electron::ScopedAllowBlockingForElectron allow_blocking; - len = file_.ReadAtCurrentPos(buf.data(), buf.size()); - } - if (len != static_cast(buf.size())) { - PLOG(ERROR) << "Failed to read header from " << path_.value(); - return false; + if (!file_.ReadAtCurrentPosAndCheck(buf)) { + PLOG(ERROR) << "Failed to read header from " << path_.value(); + return false; + } } std::string header; - if (!base::PickleIterator(base::Pickle::WithData(base::as_byte_span(buf))) - .ReadString(&header)) { + if (!base::PickleIterator(base::Pickle::WithData(buf)).ReadString(&header)) { LOG(ERROR) << "Failed to parse header from " << path_.value(); return false; } diff --git a/shell/common/asar/scoped_temporary_file.cc b/shell/common/asar/scoped_temporary_file.cc index 1ad0ccf55ae2..e82087fef935 100644 --- a/shell/common/asar/scoped_temporary_file.cc +++ b/shell/common/asar/scoped_temporary_file.cc @@ -63,20 +63,15 @@ bool ScopedTemporaryFile::InitFromFile( return false; electron::ScopedAllowBlockingForElectron allow_blocking; - std::vector buf(size); - int len = src->Read(offset, buf.data(), buf.size()); - if (len != static_cast(size)) + std::vector buf(size); + if (!src->ReadAndCheck(offset, buf)) return false; if (integrity) - ValidateIntegrityOrDie(base::as_byte_span(buf), *integrity); + ValidateIntegrityOrDie(buf, *integrity); base::File dest(path_, base::File::FLAG_OPEN | base::File::FLAG_WRITE); - if (!dest.IsValid()) - return false; - - return dest.WriteAtCurrentPos(buf.data(), buf.size()) == - static_cast(size); + return dest.IsValid() && dest.WriteAtCurrentPosAndCheck(buf); } } // namespace asar