diff options
author | Rolf Eike Beer <eike@sf-mail.de> | 2014-12-22 20:56:14 (GMT) |
---|---|---|
committer | Rolf Eike Beer <eike@sf-mail.de> | 2014-12-26 15:23:31 (GMT) |
commit | a9fae8ac1d952ffd3b54de6082f9729466101bb0 (patch) | |
tree | b8526293a999a44fcc52f80715bf045e92f5e0b1 /Source/cmCTest.cxx | |
parent | 1819d4ad1fb0016c20a46a0b66274b53d2b0f010 (diff) | |
download | CMake-a9fae8ac1d952ffd3b54de6082f9729466101bb0.zip CMake-a9fae8ac1d952ffd3b54de6082f9729466101bb0.tar.gz CMake-a9fae8ac1d952ffd3b54de6082f9729466101bb0.tar.bz2 |
CTest: Fix integer overflow when uploading huge files
When uploading files greater 2GB a cast to 'int' overflows, leading to a
bad alloc when passed to new. Also avoid floating point arithmetic when
integer calculations will work as well.
Reported-by: Justin Borodinsky <justin.borodinsky@gmail.com>
Diffstat (limited to 'Source/cmCTest.cxx')
-rw-r--r-- | Source/cmCTest.cxx | 7 |
1 files changed, 3 insertions, 4 deletions
diff --git a/Source/cmCTest.cxx b/Source/cmCTest.cxx index 2bf7b77..814c4e0 100644 --- a/Source/cmCTest.cxx +++ b/Source/cmCTest.cxx @@ -1688,7 +1688,7 @@ std::string cmCTest::Base64GzipEncodeFile(std::string file) //---------------------------------------------------------------------- std::string cmCTest::Base64EncodeFile(std::string file) { - long len = cmSystemTools::FileLength(file); + size_t const len = cmSystemTools::FileLength(file); cmsys::ifstream ifs(file.c_str(), std::ios::in #ifdef _WIN32 | std::ios::binary @@ -1699,8 +1699,7 @@ std::string cmCTest::Base64EncodeFile(std::string file) ifs.close(); unsigned char *encoded_buffer - = new unsigned char [ static_cast<int>( - static_cast<double>(len) * 1.5 + 5.0) ]; + = new unsigned char [ (len * 3) / 2 + 5 ]; unsigned long rlen = cmsysBase64_Encode(file_buffer, len, encoded_buffer, 1); @@ -3192,7 +3191,7 @@ bool cmCTest::CompressString(std::string& str) // Now base64 encode the resulting binary string unsigned char* base64EncodedBuffer - = new unsigned char[static_cast<int>(outSize * 1.5)]; + = new unsigned char[(outSize * 3) / 2]; unsigned long rlen = cmsysBase64_Encode(out, strm.total_out, base64EncodedBuffer, 1); |