aboutsummaryrefslogtreecommitdiffhomepage
path: root/dm/DM.cpp
diff options
context:
space:
mode:
authorGravatar Mike Klein <mtklein@chromium.org>2017-04-05 18:04:31 -0400
committerGravatar Skia Commit-Bot <skia-commit-bot@chromium.org>2017-04-05 23:08:08 +0000
commit45dcc0c42c4059c3b533b3e91d6c7fe67f6eefc7 (patch)
tree816d693bd8b28dec917760a05fb4633f13772e1f /dm/DM.cpp
parent7abfb5e1547bcbf626b2078991a9fe31c24b5d10 (diff)
Fix gather_uninteresting_hashes()
It can crash when the file length is an exact multiple of the page size. When the file size is not an exact page size multiple, SkData::MakeFromFileName() (i.e. mmap) happens to fill the rest with \0, giving us a terminating \0 for free. SkStrSplit() uses this to stop. When the file size is an exact page size multiple, there's no guaranteed \0. We might find one on the next page immediately, eventually, or we might just segfault. Whoops. To fix, copy to an SkString which ought to plop in a \0 for us. Change-Id: I51bbfdd85dfbb1c2276249d0255cf1c410ef9999 Reviewed-on: https://skia-review.googlesource.com/11409 Commit-Queue: Mike Klein <mtklein@chromium.org> Reviewed-by: Mike Klein <mtklein@chromium.org>
Diffstat (limited to 'dm/DM.cpp')
-rw-r--r--dm/DM.cpp6
1 files changed, 5 insertions, 1 deletions
diff --git a/dm/DM.cpp b/dm/DM.cpp
index 0b36e4bb87..340c338c27 100644
--- a/dm/DM.cpp
+++ b/dm/DM.cpp
@@ -329,8 +329,12 @@ static void gather_uninteresting_hashes() {
FLAGS_uninterestingHashesFile[0]);
return;
}
+
+ // Copy to a string to make sure SkStrSplit has a terminating \0 to find.
+ SkString contents((const char*)data->data(), data->size());
+
SkTArray<SkString> hashes;
- SkStrSplit((const char*)data->data(), kNewline, &hashes);
+ SkStrSplit(contents.c_str(), kNewline, &hashes);
for (const SkString& hash : hashes) {
gUninterestingHashes.add(hash);
}