summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
author Adam Lesinski <adamlesinski@google.com> 2017-04-25 15:43:15 +0000
committer android-build-merger <android-build-merger@google.com> 2017-04-25 15:43:15 +0000
commit40f7202e8145a6c4c4073b91303373594e64fb0d (patch)
tree430efa6e119bc929602c259a479d08e0c29d8702
parent79f962047bedfbc432264d517a89c48e5a6de3b4 (diff)
parent56ee63d7773660d1631e5da2c2e1c9434015af6d (diff)
Merge "AAPT2: Add better error message when processing invalid files" into oc-dev am: b9dbee430d
am: 56ee63d777 Change-Id: I87e0bf3432a0e8e7a41655eba6aa6abf1c6ec451
-rw-r--r--tools/aapt2/cmd/Compile.cpp23
1 files changed, 22 insertions, 1 deletions
diff --git a/tools/aapt2/cmd/Compile.cpp b/tools/aapt2/cmd/Compile.cpp
index 423e79069eac..b93c6ecea274 100644
--- a/tools/aapt2/cmd/Compile.cpp
+++ b/tools/aapt2/cmd/Compile.cpp
@@ -365,6 +365,21 @@ static bool FlattenXmlToOutStream(IAaptContext* context, const StringPiece& outp
return true;
}
+static bool IsValidFile(IAaptContext* context, const StringPiece& input_path) {
+ const file::FileType file_type = file::GetFileType(input_path);
+ if (file_type != file::FileType::kRegular && file_type != file::FileType::kSymlink) {
+ if (file_type == file::FileType::kDirectory) {
+ context->GetDiagnostics()->Error(DiagMessage(input_path)
+ << "resource file cannot be a directory");
+ } else {
+ context->GetDiagnostics()->Error(DiagMessage(input_path)
+ << "not a valid resource file");
+ }
+ return false;
+ }
+ return true;
+}
+
static bool CompileXml(IAaptContext* context, const CompileOptions& options,
const ResourcePathData& path_data, IArchiveWriter* writer,
const std::string& output_path) {
@@ -569,7 +584,8 @@ static bool CompileFile(IAaptContext* context, const CompileOptions& options,
std::string error_str;
Maybe<android::FileMap> f = file::MmapPath(path_data.source.path, &error_str);
if (!f) {
- context->GetDiagnostics()->Error(DiagMessage(path_data.source) << error_str);
+ context->GetDiagnostics()->Error(DiagMessage(path_data.source) << "failed to mmap file: "
+ << error_str);
return false;
}
@@ -697,6 +713,11 @@ int Compile(const std::vector<StringPiece>& args) {
context.GetDiagnostics()->Note(DiagMessage(path_data.source) << "processing");
}
+ if (!IsValidFile(&context, path_data.source.path)) {
+ error = true;
+ continue;
+ }
+
if (path_data.resource_dir == "values") {
// Overwrite the extension.
path_data.extension = "arsc";