summaryrefslogtreecommitdiff
path: root/simpleperf
diff options
context:
space:
mode:
authorYabin Cui <yabinc@google.com>2016-12-13 17:49:19 -0800
committerYabin Cui <yabinc@google.com>2016-12-13 17:49:19 -0800
commit044861ba8d71688940b6500f68458fae0791517c (patch)
tree267a1f73589087ec4059c305fd9d86708d3f1928 /simpleperf
parent923268ef1e53edb06f088c11193e2214053d48df (diff)
downloadextras-044861ba8d71688940b6500f68458fae0791517c.tar.gz
simpleperf: check invalid perf.data.
Bug: http://b/33558210 Test: run simpleperf_unit_test. Change-Id: If5a1f7fc9c436a39776f80f1e52479f1cd7ff407
Diffstat (limited to 'simpleperf')
-rw-r--r--simpleperf/cmd_report_test.cpp4
-rw-r--r--simpleperf/get_test_data.h3
-rw-r--r--simpleperf/record_file_reader.cpp9
-rw-r--r--simpleperf/testdata/invalid_perf.databin0 -> 1024 bytes
4 files changed, 15 insertions, 1 deletions
diff --git a/simpleperf/cmd_report_test.cpp b/simpleperf/cmd_report_test.cpp
index 16b2f69d..18c8deab 100644
--- a/simpleperf/cmd_report_test.cpp
+++ b/simpleperf/cmd_report_test.cpp
@@ -443,6 +443,10 @@ TEST_F(ReportCommandTest, kallsyms_option) {
ASSERT_NE(content.find("FakeKernelSymbol"), std::string::npos);
}
+TEST_F(ReportCommandTest, invalid_perf_data) {
+ ASSERT_FALSE(ReportCmd()->Run({"-i", GetTestData(INVALID_PERF_DATA)}));
+}
+
#if defined(__linux__)
#include "event_selection_set.h"
diff --git a/simpleperf/get_test_data.h b/simpleperf/get_test_data.h
index 4550843e..9fb2293c 100644
--- a/simpleperf/get_test_data.h
+++ b/simpleperf/get_test_data.h
@@ -102,4 +102,7 @@ static const std::string PERF_DATA_GENERATED_BY_LINUX_PERF = "generated_by_linux
// generated by `simpleperf record -g ls`.
static const std::string PERF_DATA_MAX_STACK_AND_PERCENT_LIMIT = "perf_test_max_stack_and_percent_limit.data";
+// generated by `dd if=/dev/zero of=invalid_perf.data bs=1024 count=1`.
+static const std::string INVALID_PERF_DATA = "invalid_perf.data";
+
#endif // SIMPLE_PERF_GET_TEST_DATA_H_
diff --git a/simpleperf/record_file_reader.cpp b/simpleperf/record_file_reader.cpp
index bff8ba16..06a2644d 100644
--- a/simpleperf/record_file_reader.cpp
+++ b/simpleperf/record_file_reader.cpp
@@ -66,7 +66,14 @@ bool RecordFileReader::Close() {
}
bool RecordFileReader::ReadHeader() {
- return Read(&header_, sizeof(header_));
+ if (!Read(&header_, sizeof(header_))) {
+ return false;
+ }
+ if (memcmp(header_.magic, PERF_MAGIC, sizeof(header_.magic)) != 0) {
+ LOG(ERROR) << filename_ << " is not a valid profiling record file.";
+ return false;
+ }
+ return true;
}
bool RecordFileReader::ReadAttrSection() {
diff --git a/simpleperf/testdata/invalid_perf.data b/simpleperf/testdata/invalid_perf.data
new file mode 100644
index 00000000..06d74050
--- /dev/null
+++ b/simpleperf/testdata/invalid_perf.data
Binary files differ