This commit is contained in:
Samuel Attard 2021-09-09 19:52:23 -07:00 коммит произвёл GitHub
Родитель 57d088517c
Коммит fb539f15d0
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: 4AEE18F83AFDEB23
5 изменённых файлов: 25 добавлений и 11 удалений

Просмотреть файл

@ -24,6 +24,8 @@ AsarFileValidator::AsarFileValidator(IntegrityPayload integrity,
max_block_ = integrity_.blocks.size() - 1;
}
AsarFileValidator::~AsarFileValidator() = default;
void AsarFileValidator::OnRead(base::span<char> buffer,
mojo::FileDataSource::ReadResult* result) {
DCHECK(!done_reading_);

Просмотреть файл

@ -19,11 +19,12 @@ namespace asar {
class AsarFileValidator : public mojo::FilteredDataSource::Filter {
public:
AsarFileValidator(IntegrityPayload integrity, base::File file);
~AsarFileValidator() override;
void OnRead(base::span<char> buffer,
mojo::FileDataSource::ReadResult* result);
mojo::FileDataSource::ReadResult* result) override;
void OnDone();
void OnDone() override;
void SetRange(uint64_t read_start, uint64_t extra_read, uint64_t read_max);
void SetCurrentBlock(int current_block);

Просмотреть файл

@ -157,7 +157,9 @@ class AsarURLLoader : public network::mojom::URLLoader {
std::unique_ptr<mojo::DataPipeProducer::DataSource> readable_data_source;
mojo::FileDataSource* file_data_source_raw = file_data_source.get();
AsarFileValidator* file_validator_raw = nullptr;
uint32_t block_size = 0;
if (info.integrity.has_value()) {
block_size = info.integrity.value().block_size;
auto asar_validator = std::make_unique<AsarFileValidator>(
std::move(info.integrity.value()), std::move(file));
file_validator_raw = asar_validator.get();
@ -232,15 +234,13 @@ class AsarURLLoader : public network::mojom::URLLoader {
first_byte_to_send = read_result.bytes_read;
total_bytes_to_send -= write_size;
} else if (is_verifying_file &&
first_byte_to_send >=
static_cast<uint64_t>(info.integrity.value().block_size)) {
first_byte_to_send >= static_cast<uint64_t>(block_size)) {
// If validation is active and the range of bytes the request wants starts
// beyond the first block we need to read the next 4MB-1KB to validate
// that block. Then we can skip ahead to the target block in the SetRange
// call below If we hit this case it is assumed that none of the data read
// will be needed by the producer
uint64_t bytes_to_drop =
info.integrity.value().block_size - net::kMaxBytesToSniff;
uint64_t bytes_to_drop = block_size - net::kMaxBytesToSniff;
total_bytes_dropped_from_head += bytes_to_drop;
std::vector<char> abandoned_buffer(bytes_to_drop);
auto abandon_read_result =
@ -282,7 +282,6 @@ class AsarURLLoader : public network::mojom::URLLoader {
}
if (is_verifying_file) {
uint32_t block_size = info.integrity.value().block_size;
int start_block = first_byte_to_send / block_size;
// If we're starting from the first block, we might not be starting from

Просмотреть файл

@ -157,6 +157,15 @@ bool FillFileInfoWithNode(Archive::FileInfo* info,
} // namespace
IntegrityPayload::IntegrityPayload()
: algorithm(HashAlgorithm::NONE), block_size(0) {}
IntegrityPayload::~IntegrityPayload() = default;
IntegrityPayload::IntegrityPayload(const IntegrityPayload& other) = default;
Archive::FileInfo::FileInfo()
: unpacked(false), executable(false), size(0), offset(0) {}
Archive::FileInfo::~FileInfo() = default;
Archive::Archive(const base::FilePath& path)
: initialized_(false), path_(path), file_(base::File::FILE_OK) {
base::ThreadRestrictions::ScopedAllowIO allow_io;
@ -270,11 +279,11 @@ bool Archive::Init() {
#if !defined(OS_MAC)
absl::optional<IntegrityPayload> Archive::HeaderIntegrity() const {
return absl::optional<IntegrityPayload>();
return absl::nullopt;
}
absl::optional<base::FilePath> Archive::RelativePath() const {
return absl::optional<base::FilePath>();
return absl::nullopt;
}
#endif

Просмотреть файл

@ -29,7 +29,9 @@ enum HashAlgorithm {
};
struct IntegrityPayload {
IntegrityPayload() : algorithm(HashAlgorithm::NONE), block_size(0) {}
IntegrityPayload();
~IntegrityPayload();
IntegrityPayload(const IntegrityPayload& other);
HashAlgorithm algorithm;
std::string hash;
uint32_t block_size;
@ -41,7 +43,8 @@ struct IntegrityPayload {
class Archive {
public:
struct FileInfo {
FileInfo() : unpacked(false), executable(false), size(0), offset(0) {}
FileInfo();
~FileInfo();
bool unpacked;
bool executable;
uint32_t size;