diff options
author | A. Cody Schuffelen <schuffelen@google.com> | 2022-07-12 20:41:29 +0000 |
---|---|---|
committer | Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com> | 2022-07-12 20:41:29 +0000 |
commit | 136b0d51d44f0c00525a972373787387ebfcd3bd (patch) | |
tree | bb14cf53cb35946842caafac43fe0eb7ba549ca6 | |
parent | cc0e0fedc24468f13e1e78c5714dfe46b1c7daa5 (diff) | |
parent | 3b296c3b375456e4e012dcaa1739c813f2a7d284 (diff) | |
download | cuttlefish-136b0d51d44f0c00525a972373787387ebfcd3bd.tar.gz |
Fix crash in `ReadFile` when the input file is empty. am: 8a25a05724 am: 3b296c3b37
Original change: https://googleplex-android-review.googlesource.com/c/device/google/cuttlefish/+/19224561
Change-Id: I0143459c3228a92a6e025a5b06437e7dcb484717
Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
-rw-r--r-- | common/libs/utils/files.cpp | 4 |
1 files changed, 4 insertions, 0 deletions
diff --git a/common/libs/utils/files.cpp b/common/libs/utils/files.cpp index ea84b3221..f3a6eabf3 100644 --- a/common/libs/utils/files.cpp +++ b/common/libs/utils/files.cpp @@ -147,6 +147,10 @@ std::string ReadFile(const std::string& file) { std::string contents; std::ifstream in(file, std::ios::in | std::ios::binary); in.seekg(0, std::ios::end); + if (in.fail()) { + // TODO(schuffelen): Return a failing Result instead + return ""; + } contents.resize(in.tellg()); in.seekg(0, std::ios::beg); in.read(&contents[0], contents.size()); |