[Scummvm-git-logs] scummvm master -> b093c9d6b5a077e3a23943a47b418c23044fc155
lephilousophe
lephilousophe at users.noreply.github.com
Tue Dec 1 19:07:16 UTC 2020
This automated email contains information about 2 new commits which have been
pushed to the 'scummvm' repo located at https://github.com/scummvm/scummvm .
Summary:
58f728a042 COMMON: Fix UTF-16 decoding
b093c9d6b5 GRAPHICS: Fix decoding of TTF font names
Commit: 58f728a042a7a5465f84321f377db9978322dafe
https://github.com/scummvm/scummvm/commit/58f728a042a7a5465f84321f377db9978322dafe
Author: Le Philousophe (lephilousophe at users.noreply.github.com)
Date: 2020-12-01T19:43:20+01:00
Commit Message:
COMMON: Fix UTF-16 decoding
In case of 4-bytes codepoints, length wasn't decreased.
If codepoint is invalid don't eat the second code unit to let
resynchronization happen.
Changed paths:
common/str-enc.cpp
diff --git a/common/str-enc.cpp b/common/str-enc.cpp
index c1d821edce..0bb288eeac 100644
--- a/common/str-enc.cpp
+++ b/common/str-enc.cpp
@@ -621,22 +621,26 @@ void String::encodeUTF8(const U32String &src) {
}
#define decodeUTF16Template(suffix, read) \
-Common::U32String U32String::decodeUTF16 ## suffix (const uint16 *start, uint len) { \
+Common::U32String U32String::decodeUTF16 ## suffix (const uint16 *start, uint len) { \
const uint16 *ptr = start; \
Common::U32String dst; \
dst.ensureCapacity(len, false); \
\
- while (len-- > 0) { \
+ while (len > 0) { \
uint16 c = read(ptr++); \
+ len--; \
if (c >= 0xD800 && c <= 0xDBFF && len > 0) { \
- uint16 low = read(ptr++); \
- if (low >= 0xDC00 && low <= 0xDFFF) \
- dst += ((c & 0x3ff) << 10) \
- | (low & 0x3ff); \
- else \
+ uint16 low = read(ptr); \
+ if (low >= 0xDC00 && low <= 0xDFFF) { \
+ /* low is OK, we can advance pointer */ \
+ ptr++; len--; \
+ dst += ((c & 0x3ff) << 10) \
+ | (low & 0x3ff); \
+ } else { \
dst += invalidCode; \
+ } \
continue; \
- } \
+ } \
\
if (c >= 0xD800 && c <= 0xDFFF) { \
dst += invalidCode; \
@@ -668,7 +672,7 @@ uint16 *U32String::encodeUTF16 ## suffix (uint *len) const { \
} \
\
write(ptr, 0); \
- if (len) \
+ if (len) \
*len = ptr - out; \
\
return out; \
Commit: b093c9d6b5a077e3a23943a47b418c23044fc155
https://github.com/scummvm/scummvm/commit/b093c9d6b5a077e3a23943a47b418c23044fc155
Author: Le Philousophe (lephilousophe at users.noreply.github.com)
Date: 2020-12-01T20:03:07+01:00
Commit Message:
GRAPHICS: Fix decoding of TTF font names
This fixes a buffer overflow when decoding font Unicode name as length
provided to decodeUTF16BE is in code units and not in bytes (twice less).
Changed paths:
graphics/fonts/ttf.cpp
diff --git a/graphics/fonts/ttf.cpp b/graphics/fonts/ttf.cpp
index d9bf6bcc7b..fd48aee03c 100644
--- a/graphics/fonts/ttf.cpp
+++ b/graphics/fonts/ttf.cpp
@@ -861,7 +861,7 @@ Font *loadTTFFontFromArchive(const Common::String &filename, int size, TTFSizeMo
}
static bool matchFaceName(const Common::U32String &faceName, const FT_Face &face) {
- if (faceName == Common::U32String(face->family_name)) {
+ if (faceName == Common::U32String(face->family_name, Common::kASCII)) {
// International name in ASCII match
return true;
}
@@ -883,21 +883,22 @@ static bool matchFaceName(const Common::U32String &faceName, const FT_Face &face
if (aname.encoding_id == TT_MS_ID_SYMBOL_CS ||
aname.encoding_id == TT_MS_ID_UNICODE_CS) {
// MS local name in UTF-16
- Common::U32String localName = Common::U32String::decodeUTF16BE((uint16 *) aname.string, aname.string_len);
+ // string_len is in bytes length, we take wchar_t length
+ Common::U32String localName = Common::U32String::decodeUTF16BE((uint16 *) aname.string, aname.string_len / 2);
if (faceName == localName) {
return true;
}
} else {
- // No conversion
- if (faceName == Common::U32String((char *)aname.string, aname.string_len)) {
+ // No conversion: try to match with 1 byte encoding
+ if (faceName == Common::U32String((char *)aname.string, aname.string_len, Common::kLatin1)) {
return true;
}
}
} else if (aname.platform_id == TT_PLATFORM_MACINTOSH &&
aname.language_id != TT_MAC_LANGID_ENGLISH) {
// No conversion
- if (faceName == Common::U32String((char *)aname.string, aname.string_len)) {
+ if (faceName == Common::U32String((char *)aname.string, aname.string_len, Common::kLatin1)) {
return true;
}
}
More information about the Scummvm-git-logs
mailing list