Skip to content

Commit

Permalink
Fix TOCTOU issues, switch to fstat (#7067)
Browse files Browse the repository at this point in the history
Signed-off-by: Logan Adams <loadams@microsoft.com>
  • Loading branch information
loadams authored Feb 24, 2025
1 parent 38327e0 commit 9d820e4
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 deletions csrc/aio/common/deepspeed_aio_common.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -284,12 +284,13 @@ int open_file(const char* filename, const bool read_op)

int regular_read(const char* filename, std::vector<char>& buffer)
{
int64_t num_bytes;
const auto f_size = get_file_size(filename, num_bytes);
assert(f_size != -1);
buffer.resize(num_bytes);
const auto fd = open(filename, O_RDONLY, 0600);
assert(fd != -1);
struct stat fs;
const auto result = fstat(fd, &fs);
assert(result != -1);
int64_t num_bytes = fs.st_size;
buffer.resize(num_bytes);
int64_t read_bytes = 0;
auto r = 0;
do {
Expand Down

0 comments on commit 9d820e4

Please sign in to comment.