summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorWouter van Oortmerssen <wvo@google.com>2016-01-08 13:10:25 -0800
committerWouter van Oortmerssen <wvo@google.com>2016-01-08 13:10:25 -0800
commit42c20d7a6940b951f2523aa957000a79697bea59 (patch)
tree6649aec72c4d6aec561bd28ab7794433105b10ff /src
parent63b526db52d562b45c64f1dc6b8185fe8c42c19e (diff)
downloadflatbuffers-42c20d7a6940b951f2523aa957000a79697bea59.tar.gz
flatbuffers-42c20d7a6940b951f2523aa957000a79697bea59.tar.bz2
flatbuffers-42c20d7a6940b951f2523aa957000a79697bea59.zip
Make flatc check for binary files to avoid accidental parsing.
Binary file arguments to flatc have to be preceded by -- to identify them, forgetting this however results in them being attempted to be parsed as schema/json, with cryptic errors. This instead gives an error if 0 bytes are contained in your text file. Bug: 22069056 Change-Id: I226bf651dcb016f18d7c8ffadcf23466a1fc0b87 Tested: on Linux.
Diffstat (limited to 'src')
-rw-r--r--src/flatc.cpp6
1 files changed, 5 insertions, 1 deletions
diff --git a/src/flatc.cpp b/src/flatc.cpp
index 97ee7938..dae107e4 100644
--- a/src/flatc.cpp
+++ b/src/flatc.cpp
@@ -117,7 +117,7 @@ static void Error(const std::string &err, bool usage, bool show_exe_name) {
" This may crash flatc given a mismatched schema.\n"
" --proto Input is a .proto, translate to .fbs.\n"
" --schema Serialize schemas instead of JSON (use with -b)\n"
- "FILEs may depend on declarations in earlier files.\n"
+ "FILEs may be schemas, or JSON files (conforming to preceding schema)\n"
"FILEs after the -- must be binary flatbuffer format files.\n"
"Output files are named using the base file name of the input,\n"
"and written to the current directory or the path given by -o.\n"
@@ -251,6 +251,10 @@ int main(int argc, const char *argv[]) {
}
}
} else {
+ // Check if file contains 0 bytes.
+ if (contents.length() != strlen(contents.c_str())) {
+ Error("input file appears to be binary: " + *file_it, true);
+ }
if (flatbuffers::GetExtension(*file_it) == "fbs") {
// If we're processing multiple schemas, make sure to start each
// one from scratch. If it depends on previous schemas it must do