From 5f11abd31fa8cfa723f54bd1c98ce4e27e7d3c77 Mon Sep 17 00:00:00 2001 From: Raph Levien Date: Thu, 23 Oct 2014 14:54:42 -0700 Subject: [PATCH] Silently ignore invalid rangeOffset values Some fonts contain a cmap segment for char 0xffff that contains an invalid rangeOffset. This was rejected by the existing code, which means the font is considered to have empty Unicode coverage. This patch just discards the invalid segment (consistent with OpenType Sanitizer), making the custom font display. Bug: 18106256 Change-Id: Icc8616a3030f80e62db906332be64d434ae72ea2 --- libs/minikin/CmapCoverage.cpp | 23 ++++++++++++----------- 1 file changed, 12 insertions(+), 11 deletions(-) diff --git a/libs/minikin/CmapCoverage.cpp b/libs/minikin/CmapCoverage.cpp index 4156d69d5a1..75033729e31 100644 --- a/libs/minikin/CmapCoverage.cpp +++ b/libs/minikin/CmapCoverage.cpp @@ -16,9 +16,8 @@ // Determine coverage of font given its raw "cmap" OpenType table -#ifdef PRINTF_DEBUG -#include -#endif +#define LOG_TAG "Minikin" +#include #include using std::vector; @@ -38,8 +37,8 @@ static uint32_t readU32(const uint8_t* data, size_t offset) { } static void addRange(vector &coverage, uint32_t start, uint32_t end) { -#ifdef PRINTF_DEBUG - printf("adding range %d-%d\n", start, end); +#ifdef VERBOSE_DEBUG + ALOGD("adding range %d-%d\n", start, end); #endif if (coverage.empty() || coverage.back() < start) { coverage.push_back(start); @@ -82,7 +81,8 @@ static bool getCoverageFormat4(vector& coverage, const uint8_t* data, uint32_t actualRangeOffset = kHeaderSize + 6 * segCount + rangeOffset + (i + j - start) * 2; if (actualRangeOffset + 2 > size) { - return false; + // invalid rangeOffset is considered a "warning" by OpenType Sanitizer + continue; } int glyphId = readU16(data, actualRangeOffset); if (glyphId != 0) { @@ -146,8 +146,8 @@ bool CmapCoverage::getCoverage(SparseBitSet& coverage, const uint8_t* cmap_data, bestTable = i; } } -#ifdef PRINTF_DEBUG - printf("best table = %d\n", bestTable); +#ifdef VERBOSE_DEBUG + ALOGD("best table = %d\n", bestTable); #endif if (bestTable < 0) { return false; @@ -168,10 +168,11 @@ bool CmapCoverage::getCoverage(SparseBitSet& coverage, const uint8_t* cmap_data, if (success) { coverage.initFromRanges(&coverageVec.front(), coverageVec.size() >> 1); } -#ifdef PRINTF_DEBUG - for (int i = 0; i < coverageVec.size(); i += 2) { - printf("%x:%x\n", coverageVec[i], coverageVec[i + 1]); +#ifdef VERBOSE_DEBUG + for (size_t i = 0; i < coverageVec.size(); i += 2) { + ALOGD("%x:%x\n", coverageVec[i], coverageVec[i + 1]); } + ALOGD("success = %d", success); #endif return success; }