SkUTF16_CountUnichars to error instead of assert.
Update SkUTF16_CountUnichars to return -1 on invalid input instead of simply asserting in debug. This also removes the unneeded checks for zero length input. This also updates SkPaintPriv::ValidCountText and its documentation to reflect the reality that it returns -1 on invalid data. Bug: skia:8156 Change-Id: Ief227b7dec9d1e823b93e9061558f8412791fc09 Reviewed-on: https://skia-review.googlesource.com/142168 Reviewed-by: Hal Canary <halcanary@google.com> Commit-Queue: Ben Wagner <bungeman@google.com>
This commit is contained in:
parent
715d08c381
commit
0afc75e754
@ -91,19 +91,16 @@ bool SkPaintPriv::ShouldDither(const SkPaint& p, SkColorType dstCT) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
int SkPaintPriv::ValidCountText(const void* text, size_t length, SkPaint::TextEncoding encoding) {
|
int SkPaintPriv::ValidCountText(const void* text, size_t length, SkPaint::TextEncoding encoding) {
|
||||||
if (length == 0) {
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
switch (encoding) {
|
switch (encoding) {
|
||||||
case SkPaint::kUTF8_TextEncoding: return SkUTF8_CountUnichars(text, length);
|
case SkPaint::kUTF8_TextEncoding: return SkUTF8_CountUnichars(text, length);
|
||||||
case SkPaint::kUTF16_TextEncoding: return SkUTF16_CountUnichars(text, length);
|
case SkPaint::kUTF16_TextEncoding: return SkUTF16_CountUnichars(text, length);
|
||||||
case SkPaint::kUTF32_TextEncoding: return SkUTF32_CountUnichars(text, length);
|
case SkPaint::kUTF32_TextEncoding: return SkUTF32_CountUnichars(text, length);
|
||||||
case SkPaint::kGlyphID_TextEncoding:
|
case SkPaint::kGlyphID_TextEncoding:
|
||||||
if (SkIsAlign2(intptr_t(text)) && SkIsAlign2(length)) {
|
if (!SkIsAlign2(intptr_t(text)) || !SkIsAlign2(length)) {
|
||||||
return length >> 1;
|
return -1;
|
||||||
}
|
}
|
||||||
break;
|
return length >> 1;
|
||||||
}
|
}
|
||||||
return 0;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -68,7 +68,7 @@ public:
|
|||||||
|
|
||||||
static bool ShouldDither(const SkPaint&, SkColorType);
|
static bool ShouldDither(const SkPaint&, SkColorType);
|
||||||
|
|
||||||
// returns 0 if buffer is invalid for specified encoding
|
// returns -1 if buffer is invalid for specified encoding
|
||||||
static int ValidCountText(const void* text, size_t length, SkPaint::TextEncoding);
|
static int ValidCountText(const void* text, size_t length, SkPaint::TextEncoding);
|
||||||
|
|
||||||
static SkTypeface* GetTypefaceOrDefault(const SkPaint& paint) {
|
static SkTypeface* GetTypefaceOrDefault(const SkPaint& paint) {
|
||||||
|
@ -86,10 +86,6 @@ int SkUTF8_CountUnichars(const char utf8[]) {
|
|||||||
int SkUTF8_CountUnichars(const void* text, size_t byteLength) {
|
int SkUTF8_CountUnichars(const void* text, size_t byteLength) {
|
||||||
SkASSERT(text);
|
SkASSERT(text);
|
||||||
const char* utf8 = static_cast<const char*>(text);
|
const char* utf8 = static_cast<const char*>(text);
|
||||||
if (byteLength == 0) {
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
int count = 0;
|
int count = 0;
|
||||||
const char* stop = utf8 + byteLength;
|
const char* stop = utf8 + byteLength;
|
||||||
|
|
||||||
@ -262,9 +258,6 @@ int SkUTF16_CountUnichars(const uint16_t src[]) {
|
|||||||
// returns -1 on error
|
// returns -1 on error
|
||||||
int SkUTF16_CountUnichars(const void* text, size_t byteLength) {
|
int SkUTF16_CountUnichars(const void* text, size_t byteLength) {
|
||||||
SkASSERT(text);
|
SkASSERT(text);
|
||||||
if (byteLength == 0) {
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
if (!SkIsAlign2(intptr_t(text)) || !SkIsAlign2(byteLength)) {
|
if (!SkIsAlign2(intptr_t(text)) || !SkIsAlign2(byteLength)) {
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
@ -274,7 +267,9 @@ int SkUTF16_CountUnichars(const void* text, size_t byteLength) {
|
|||||||
int count = 0;
|
int count = 0;
|
||||||
while (src < stop) {
|
while (src < stop) {
|
||||||
unsigned c = *src++;
|
unsigned c = *src++;
|
||||||
SkASSERT(!SkUTF16_IsLowSurrogate(c));
|
if (SkUTF16_IsLowSurrogate(c)) {
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
if (SkUTF16_IsHighSurrogate(c)) {
|
if (SkUTF16_IsHighSurrogate(c)) {
|
||||||
if (src >= stop) {
|
if (src >= stop) {
|
||||||
return -1;
|
return -1;
|
||||||
@ -405,9 +400,6 @@ size_t SkUTF16_ToUTF8(const uint16_t utf16[], int numberOf16BitValues,
|
|||||||
|
|
||||||
// returns -1 on error
|
// returns -1 on error
|
||||||
int SkUTF32_CountUnichars(const void* text, size_t byteLength) {
|
int SkUTF32_CountUnichars(const void* text, size_t byteLength) {
|
||||||
if (byteLength == 0) {
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
if (!SkIsAlign4(intptr_t(text)) || !SkIsAlign4(byteLength)) {
|
if (!SkIsAlign4(intptr_t(text)) || !SkIsAlign4(byteLength)) {
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user