fixed off-by-one error with offSize

This commit is contained in:
Michiharu Ariza 2018-09-11 16:20:39 -07:00
parent 1499029a96
commit 5b453f77f8
3 changed files with 6 additions and 5 deletions

View File

@ -42,9 +42,10 @@ template<typename Type>
static inline const Type& StructAtOffsetOrNull(const void *P, unsigned int offset) static inline const Type& StructAtOffsetOrNull(const void *P, unsigned int offset)
{ return offset? (* reinterpret_cast<const Type*> ((const char *) P + offset)): Null(Type); } { return offset? (* reinterpret_cast<const Type*> ((const char *) P + offset)): Null(Type); }
inline unsigned int calcOffSize(unsigned int offset) inline unsigned int calcOffSize(unsigned int dataSize)
{ {
unsigned int size = 1; unsigned int size = 1;
unsigned int offset = dataSize + 1;
while ((offset & ~0xFF) != 0) while ((offset & ~0xFF) != 0)
{ {
size++; size++;
@ -493,7 +494,7 @@ struct FDArray : CFFIndexOf<COUNT, FontDict>
if (!fdmap.excludes (i)) if (!fdmap.excludes (i))
dictsSize += FontDict::calculate_serialized_size (fontDicts[i], opszr); dictsSize += FontDict::calculate_serialized_size (fontDicts[i], opszr);
offSize_ = calcOffSize (dictsSize + 1); offSize_ = calcOffSize (dictsSize);
return CFFIndex<COUNT>::calculate_serialized_size (offSize_, fdCount, dictsSize); return CFFIndex<COUNT>::calculate_serialized_size (offSize_, fdCount, dictsSize);
} }
}; };

View File

@ -635,7 +635,7 @@ struct cff_subset_plan {
if (!fdmap.excludes (i)) if (!fdmap.excludes (i))
dictsSize += FontDict::calculate_serialized_size (acc.fontDicts[i], fontSzr); dictsSize += FontDict::calculate_serialized_size (acc.fontDicts[i], fontSzr);
offsets.FDArrayInfo.offSize = calcOffSize (dictsSize + 1); offsets.FDArrayInfo.offSize = calcOffSize (dictsSize);
final_size += CFF1Index::calculate_serialized_size (offsets.FDArrayInfo.offSize, subset_fdcount, dictsSize); final_size += CFF1Index::calculate_serialized_size (offsets.FDArrayInfo.offSize, subset_fdcount, dictsSize);
} }
@ -650,7 +650,7 @@ struct cff_subset_plan {
subset_charstrings.push (str); subset_charstrings.push (str);
dataSize += flatstr.len; dataSize += flatstr.len;
} }
offsets.charStringsInfo.offSize = calcOffSize (dataSize + 1); offsets.charStringsInfo.offSize = calcOffSize (dataSize);
final_size += CFF1CharStrings::calculate_serialized_size (offsets.charStringsInfo.offSize, plan->glyphs.len, dataSize); final_size += CFF1CharStrings::calculate_serialized_size (offsets.charStringsInfo.offSize, plan->glyphs.len, dataSize);
} }

View File

@ -269,7 +269,7 @@ struct cff2_subset_plan {
subset_charstrings.push (str); subset_charstrings.push (str);
dataSize += flatstr.len; dataSize += flatstr.len;
} }
offsets.charStringsInfo.offSize = calcOffSize (dataSize + 1); offsets.charStringsInfo.offSize = calcOffSize (dataSize);
final_size += CFF2CharStrings::calculate_serialized_size (offsets.charStringsInfo.offSize, plan->glyphs.len, dataSize); final_size += CFF2CharStrings::calculate_serialized_size (offsets.charStringsInfo.offSize, plan->glyphs.len, dataSize);
} }