fix: check ftell() return value to prevent SIZE_MAX allocation

ftell() returns -1 on failure, which when cast to size_t becomes
SIZE_MAX, causing new char[SIZE_MAX] to crash. Added return value
check and early return with empty result on failure.

Signed-off-by: Srikanth Patchava <spatchava@meta.com>
Signed-off-by: Srikanth Patchava <srikanth.patchava@outlook.com>
This commit is contained in:
Srikanth Patchava 2026-04-24 22:02:53 -07:00
parent fab81cb483
commit 96b7206ba8
25 changed files with 5 additions and 1 deletions

0
googlemock/test/gmock_leak_test.py Executable file → Normal file
View File

0
googlemock/test/gmock_output_test.py Executable file → Normal file
View File

0
googlemock/test/gmock_test_utils.py Executable file → Normal file
View File

View File

@ -1258,7 +1258,11 @@ std::string GetCapturedStderr() {
size_t GetFileSize(FILE* file) {
fseek(file, 0, SEEK_END);
return static_cast<size_t>(ftell(file));
const long size = ftell(file);
if (size < 0) {
return 0;
}
return static_cast<size_t>(size);
}
std::string ReadEntireFile(FILE* file) {

View File

0
googletest/test/googletest-catch-exceptions-test.py Executable file → Normal file
View File

0
googletest/test/googletest-color-test.py Executable file → Normal file
View File

0
googletest/test/googletest-env-var-test.py Executable file → Normal file
View File

View File

0
googletest/test/googletest-failfast-unittest.py Executable file → Normal file
View File

0
googletest/test/googletest-filter-unittest.py Executable file → Normal file
View File

0
googletest/test/googletest-list-tests-unittest.py Executable file → Normal file
View File

0
googletest/test/googletest-output-test.py Executable file → Normal file
View File

0
googletest/test/googletest-setuptestsuite-test.py Executable file → Normal file
View File

0
googletest/test/googletest-shuffle-test.py Executable file → Normal file
View File

0
googletest/test/googletest-throw-on-failure-test.py Executable file → Normal file
View File

0
googletest/test/googletest-uninitialized-test.py Executable file → Normal file
View File

0
googletest/test/gtest_help_test.py Executable file → Normal file
View File

0
googletest/test/gtest_skip_check_output_test.py Executable file → Normal file
View File

View File

0
googletest/test/gtest_test_utils.py Executable file → Normal file
View File

0
googletest/test/gtest_testbridge_test.py Executable file → Normal file
View File

0
googletest/test/gtest_xml_outfiles_test.py Executable file → Normal file
View File

0
googletest/test/gtest_xml_output_unittest.py Executable file → Normal file
View File

0
googletest/test/gtest_xml_test_utils.py Executable file → Normal file
View File