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>
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);
}