From e1f7044f288b8743da2f0ed3478839bdab4d0e95 Mon Sep 17 00:00:00 2001 From: Guogang Li Date: Wed, 10 Jan 2024 09:03:56 -0800 Subject: [PATCH] Fixed the bug to get file size PiperOrigin-RevId: 597266370 --- internal/platform/implementation/windows/file.cc | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/internal/platform/implementation/windows/file.cc b/internal/platform/implementation/windows/file.cc index 0ce81ed7..4102602d 100644 --- a/internal/platform/implementation/windows/file.cc +++ b/internal/platform/implementation/windows/file.cc @@ -42,6 +42,13 @@ IOFile::IOFile(const absl::string_view file_path, size_t size) file_.open(wide_path, std::ios::binary | std::ios::in | std::ios::ate); total_size_ = file_.tellg(); + if (total_size_ == -1) { + // Unsure why it consistently returns -1 when the file size exceeds 2GB. If + // obtaining the file size through tellg fails, use the size provided + // in the parameters. + total_size_ = size; + } + file_.seekg(0); }