Skip to content

Commit

Permalink
fix: Verify file status prior to access
Browse files Browse the repository at this point in the history
Bug: b/377794049
Change-Id: I60654235b0fc8c4851092205a36481d247491a3b
GitOrigin-RevId: 9a5f78c9f1048730dd0c9d400874459e64c8a7fd
  • Loading branch information
Privacy Sandbox Team authored and copybara-github committed Nov 7, 2024
1 parent 0413a0d commit f496ffa
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions src/roma/byob/dispatcher/dispatcher.cc
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,16 @@ absl::StatusOr<std::string> Dispatcher::LoadBinary(
std::string code_token = ToString(Uuid::GenerateUuid());
DispatcherRequest request;
auto& payload = *request.mutable_load_binary();
std::error_code ec;
if (std::filesystem::file_status fstatus =
std::filesystem::status(binary_path, ec);
ec) {
return absl::PermissionDeniedError(absl::StrCat(
"error accessing file ", binary_path.string(), ": ", ec.message()));
} else if (fstatus.type() != std::filesystem::file_type::regular) {
return absl::InternalError(
absl::StrCat("unexpected file type for ", binary_path.string()));
}
if (std::ifstream ifs(std::move(binary_path), std::ios::binary);
ifs.is_open()) {
payload.set_binary_content(std::string(std::istreambuf_iterator<char>(ifs),
Expand Down

0 comments on commit f496ffa

Please sign in to comment.