From 4a4ae2b48992fe3a3d31af1852eb96ef783023d9 Mon Sep 17 00:00:00 2001 From: Logan Adams Date: Fri, 21 Feb 2025 14:14:06 -0800 Subject: [PATCH] Fix issues with TOCTOU, switch to fstat Signed-off-by: Logan Adams --- csrc/aio/common/deepspeed_aio_common.cpp | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/csrc/aio/common/deepspeed_aio_common.cpp b/csrc/aio/common/deepspeed_aio_common.cpp index 81c315e9a558..9d7ff5093017 100644 --- a/csrc/aio/common/deepspeed_aio_common.cpp +++ b/csrc/aio/common/deepspeed_aio_common.cpp @@ -284,12 +284,13 @@ int open_file(const char* filename, const bool read_op) int regular_read(const char* filename, std::vector& 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 {