fix: -Wunsafe-buffer-usage warnings in asar file IO (#43624)

* fix: -Wunsafe-buffer-usage warnings in ScopedTemporaryFile::InitFromFile()

* fix: -Wunsafe-buffer-usage warnings in Archive::Init()
This commit is contained in:
Charles Kerr 2024-09-09 15:34:42 -05:00 committed by GitHub
parent 5718ea4e1e
commit f1019c2c4a
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 15 additions and 25 deletions

View file

@ -201,22 +201,19 @@ bool Archive::Init() {
return false;
}
std::vector<char> buf;
int len;
std::vector<uint8_t> buf;
buf.resize(8);
{
electron::ScopedAllowBlockingForElectron allow_blocking;
len = file_.ReadAtCurrentPos(buf.data(), buf.size());
}
if (len != static_cast<int>(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<int>(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;
}