aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/core/SkPaintPriv.cpp
diff options
context:
space:
mode:
authorGravatar Mike Reed <reed@google.com>2017-12-21 13:34:24 -0500
committerGravatar Skia Commit-Bot <skia-commit-bot@chromium.org>2017-12-21 21:06:44 +0000
commit889d521d8715f4934accb630097bc09bf7ad1a32 (patch)
tree6e41a72f078156cf8e5338ebd5165df191ab97fd /src/core/SkPaintPriv.cpp
parent8957a1058e3937bc22192837d2fe87c4a8a047b7 (diff)
validate text during deserialization
Bug: 796473 Change-Id: I7b6a6c698a5b53c915ef6564852fa51ce7410a3e Reviewed-on: https://skia-review.googlesource.com/88520 Commit-Queue: Mike Reed <reed@google.com> Reviewed-by: Hal Canary <halcanary@google.com>
Diffstat (limited to 'src/core/SkPaintPriv.cpp')
-rw-r--r--src/core/SkPaintPriv.cpp19
1 files changed, 19 insertions, 0 deletions
diff --git a/src/core/SkPaintPriv.cpp b/src/core/SkPaintPriv.cpp
index 7d771f88a6..ad361a23c1 100644
--- a/src/core/SkPaintPriv.cpp
+++ b/src/core/SkPaintPriv.cpp
@@ -11,6 +11,7 @@
#include "SkImage.h"
#include "SkPaint.h"
#include "SkShaderBase.h"
+#include "SkUtils.h"
#include "SkXfermodePriv.h"
static bool changes_alpha(const SkPaint& paint) {
@@ -84,3 +85,21 @@ bool SkPaintPriv::ShouldDither(const SkPaint& p, SkColorType dstCT) {
return p.getImageFilter() || p.getMaskFilter()
|| !p.getShader() || !as_SB(p.getShader())->isConstant();
}
+
+int SkPaintPriv::ValidCountText(const void* text, size_t length, SkPaint::TextEncoding encoding) {
+ if (length == 0) {
+ return 0;
+ }
+ switch (encoding) {
+ case SkPaint::kUTF8_TextEncoding: return SkUTF8_CountUnichars(text, length);
+ case SkPaint::kUTF16_TextEncoding: return SkUTF16_CountUnichars(text, length);
+ case SkPaint::kUTF32_TextEncoding: return SkUTF32_CountUnichars(text, length);
+ case SkPaint::kGlyphID_TextEncoding:
+ if (SkIsAlign2(intptr_t(text)) && SkIsAlign2(length)) {
+ return length >> 1;
+ }
+ break;
+ }
+ return 0;
+}
+