summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlon Zakai <alonzakai@gmail.com>2017-02-02 08:58:10 -0800
committerGitHub <noreply@github.com>2017-02-02 08:58:10 -0800
commit47457e4d7d5fa750c343d288b3f5a607d27f66ff (patch)
treed4040d7920a3942919c7e584cc6ddf571fa545ed
parent5725c4376cf674378084e700073d0e3a7f3c95f3 (diff)
downloadbinaryen-47457e4d7d5fa750c343d288b3f5a607d27f66ff.tar.gz
binaryen-47457e4d7d5fa750c343d288b3f5a607d27f66ff.tar.bz2
binaryen-47457e4d7d5fa750c343d288b3f5a607d27f66ff.zip
only read first 4 bytes to check if a file is a wasm binary (#894)
-rw-r--r--src/wasm/wasm-io.cpp11
1 files changed, 8 insertions, 3 deletions
diff --git a/src/wasm/wasm-io.cpp b/src/wasm/wasm-io.cpp
index 2380f7447..c3192efbf 100644
--- a/src/wasm/wasm-io.cpp
+++ b/src/wasm/wasm-io.cpp
@@ -47,9 +47,14 @@ void ModuleReader::readBinary(std::string filename, Module& wasm) {
}
void ModuleReader::read(std::string filename, Module& wasm) {
- // see if this is a binary
- auto contents = read_file<std::vector<char>>(filename, Flags::Binary, debug ? Flags::Debug : Flags::Release);
- if (contents.size() >= 4 && contents[0] == '\0' && contents[1] == 'a' && contents[2] == 's' && contents[3] == 'm') {
+ // see if this is a wasm binary
+ std::ifstream infile;
+ std::ios_base::openmode flags = std::ifstream::in | std::ifstream::binary;
+ infile.open(filename, flags);
+ char buffer[4] = { 1, 2, 3, 4 };
+ infile.read(buffer, 4);
+ infile.close();
+ if (buffer[0] == '\0' && buffer[1] == 'a' && buffer[2] == 's' && buffer[3] == 'm') {
readBinary(filename, wasm);
} else {
// default to text