aboutsummaryrefslogtreecommitdiffhomepage
path: root/tests
diff options
context:
space:
mode:
authorGravatar Mike Reed <reed@google.com>2018-02-14 13:58:06 -0500
committerGravatar Skia Commit-Bot <skia-commit-bot@chromium.org>2018-02-14 19:25:43 +0000
commit33f38b05fb54994a39ff77c1b8681276c6d03ea3 (patch)
tree59061b12139c6e8fe4aea7797488f68cf7115360 /tests
parent0be01ccecba9c330baf4ba3840e57f34f6cdf320 (diff)
simplify size check in string
b/72956754 Bug: skia: Change-Id: I50627d9c7fe84630c496f8829608cde875512da0 Reviewed-on: https://skia-review.googlesource.com/107304 Commit-Queue: Mike Reed <reed@google.com> Reviewed-by: Herb Derby <herb@google.com>
Diffstat (limited to 'tests')
-rw-r--r--tests/StringTest.cpp21
1 files changed, 21 insertions, 0 deletions
diff --git a/tests/StringTest.cpp b/tests/StringTest.cpp
index 166637fd65..f9f76e9f21 100644
--- a/tests/StringTest.cpp
+++ b/tests/StringTest.cpp
@@ -304,3 +304,24 @@ DEF_TEST(String_Threaded, r) {
thread.join();
}
}
+
+// Ensure that the string allocate doesn't internally overflow any calculations, and accidentally
+// let us create a string with a requested length longer than we can manage.
+DEF_TEST(String_huge, r) {
+ // start testing slightly below max 32
+ size_t size = SK_MaxU32 - 16;
+ // See where we crash, and manually check that its at the right point.
+ //
+ // To test, change the false to true
+ while (false) {
+ // On a 64bit build, this should crash when size == 1 << 32, since we can't store
+ // that length in the string's header (which has a u32 slot for the length).
+ //
+ // On a 32bit build, this should crash the first time around, since we can't allocate
+ // anywhere near this amount.
+ //
+ SkString str(size);
+ size += 1;
+ }
+}
+