diff options
author | Jukka Jylänki <jujjyl@gmail.com> | 2016-03-28 15:33:57 +0300 |
---|---|---|
committer | Jukka Jylänki <jujjyl@gmail.com> | 2016-03-28 21:40:24 +0300 |
commit | 9da4e6ea0e2631f0643578e8c3603d1f5f825179 (patch) | |
tree | e63139c2f2713d3a93bb150f5c7b2cf2c5476686 /src/support/file.cpp | |
parent | ef0d9f61157ae22bd7c57cf9211bf4bdfe76284e (diff) | |
download | binaryen-9da4e6ea0e2631f0643578e8c3603d1f5f825179.tar.gz binaryen-9da4e6ea0e2631f0643578e8c3603d1f5f825179.tar.bz2 binaryen-9da4e6ea0e2631f0643578e8c3603d1f5f825179.zip |
Fix wasm::read_file() to abort if input file is too big to read in when building a 32-bit executable and size_t is not 64-bit.
Diffstat (limited to 'src/support/file.cpp')
-rw-r--r-- | src/support/file.cpp | 9 |
1 files changed, 7 insertions, 2 deletions
diff --git a/src/support/file.cpp b/src/support/file.cpp index 8813750d4..0401ea724 100644 --- a/src/support/file.cpp +++ b/src/support/file.cpp @@ -27,8 +27,13 @@ T wasm::read_file(const std::string &filename, bool debug) { exit(EXIT_FAILURE); } infile.seekg(0, std::ios::end); - size_t insize = infile.tellg(); - T input(insize + 1, '\0'); + std::streamoff insize = infile.tellg(); + if (sizeof(size_t) == 4 && insize >= 0xFFFFFFFFU) { + // Building a 32-bit executable where size_t == 32 bits, we are not able to create strings larger than 2^32 bytes in length, so must abort here. + std::cerr << "Failed opening '" << filename << "': Input file too large: " << insize << " bytes. Try rebuilding in 64-bit mode." << std::endl; + exit(EXIT_FAILURE); + } + T input((size_t)insize + 1, '\0'); infile.seekg(0); infile.read(&input[0], insize); return input; |