Simplify sanitize->check_array()
Fix a bug in CBDT sanitize, and redundant check in avar.
This commit is contained in:
parent
bc485a9812
commit
9507b05a7a
|
@ -129,7 +129,7 @@ struct BinSearchArrayOf
|
||||||
TRACE_SANITIZE (this);
|
TRACE_SANITIZE (this);
|
||||||
return_trace (header.sanitize (c) &&
|
return_trace (header.sanitize (c) &&
|
||||||
Type::static_size >= header.unitSize &&
|
Type::static_size >= header.unitSize &&
|
||||||
c->check_array (bytesZ, header.unitSize, header.nUnits));
|
c->check_array (bytesZ, header.nUnits, header.unitSize));
|
||||||
}
|
}
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
@ -480,8 +480,8 @@ struct StateTable
|
||||||
while (state < num_states)
|
while (state < num_states)
|
||||||
{
|
{
|
||||||
if (unlikely (!c->check_array (states,
|
if (unlikely (!c->check_array (states,
|
||||||
states[0].static_size * nClasses,
|
num_states,
|
||||||
num_states)))
|
states[0].static_size * nClasses)))
|
||||||
return_trace (false);
|
return_trace (false);
|
||||||
{ /* Sweep new states. */
|
{ /* Sweep new states. */
|
||||||
const HBUINT16 *stop = &states[num_states * nClasses];
|
const HBUINT16 *stop = &states[num_states * nClasses];
|
||||||
|
@ -490,9 +490,7 @@ struct StateTable
|
||||||
state = num_states;
|
state = num_states;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (unlikely (!c->check_array (entries,
|
if (unlikely (!c->check_array (entries, num_entries)))
|
||||||
entries[0].static_size,
|
|
||||||
num_entries)))
|
|
||||||
return_trace (false);
|
return_trace (false);
|
||||||
{ /* Sweep new entries. */
|
{ /* Sweep new entries. */
|
||||||
const Entry<Extra> *stop = &entries[num_entries];
|
const Entry<Extra> *stop = &entries[num_entries];
|
||||||
|
|
|
@ -648,7 +648,7 @@ struct Chain
|
||||||
!c->check_range (this, length))
|
!c->check_range (this, length))
|
||||||
return_trace (false);
|
return_trace (false);
|
||||||
|
|
||||||
if (!c->check_array (featureZ, featureZ[0].static_size, featureCount))
|
if (!c->check_array (featureZ, featureCount))
|
||||||
return_trace (false);
|
return_trace (false);
|
||||||
|
|
||||||
const ChainSubtable *subtable = &StructAtOffset<ChainSubtable> (featureZ, featureZ[0].static_size * featureCount);
|
const ChainSubtable *subtable = &StructAtOffset<ChainSubtable> (featureZ, featureZ[0].static_size * featureCount);
|
||||||
|
|
|
@ -296,7 +296,8 @@ struct hb_sanitize_context_t :
|
||||||
return likely (ok);
|
return likely (ok);
|
||||||
}
|
}
|
||||||
|
|
||||||
inline bool check_array (const void *base, unsigned int record_size, unsigned int len) const
|
template <typename T>
|
||||||
|
inline bool check_array (const T *base, unsigned int len, unsigned int record_size = T::static_size) const
|
||||||
{
|
{
|
||||||
const char *p = (const char *) base;
|
const char *p = (const char *) base;
|
||||||
bool overflows = hb_unsigned_mul_overflows (len, record_size);
|
bool overflows = hb_unsigned_mul_overflows (len, record_size);
|
||||||
|
|
|
@ -345,7 +345,7 @@ struct UnsizedArrayOf
|
||||||
inline bool sanitize_shallow (hb_sanitize_context_t *c, unsigned int count) const
|
inline bool sanitize_shallow (hb_sanitize_context_t *c, unsigned int count) const
|
||||||
{
|
{
|
||||||
TRACE_SANITIZE (this);
|
TRACE_SANITIZE (this);
|
||||||
return_trace (c->check_array (arrayZ, arrayZ[0].static_size, count));
|
return_trace (c->check_array (arrayZ, count));
|
||||||
}
|
}
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
@ -487,7 +487,7 @@ struct ArrayOf
|
||||||
inline bool sanitize_shallow (hb_sanitize_context_t *c) const
|
inline bool sanitize_shallow (hb_sanitize_context_t *c) const
|
||||||
{
|
{
|
||||||
TRACE_SANITIZE (this);
|
TRACE_SANITIZE (this);
|
||||||
return_trace (len.sanitize (c) && c->check_array (arrayZ, Type::static_size, len));
|
return_trace (len.sanitize (c) && c->check_array (arrayZ, len));
|
||||||
}
|
}
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
@ -596,7 +596,7 @@ struct HeadlessArrayOf
|
||||||
{
|
{
|
||||||
TRACE_SANITIZE (this);
|
TRACE_SANITIZE (this);
|
||||||
return_trace (len.sanitize (c) &&
|
return_trace (len.sanitize (c) &&
|
||||||
(!len || c->check_array (arrayZ, Type::static_size, len - 1)));
|
(!len || c->check_array (arrayZ, len - 1)));
|
||||||
}
|
}
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
|
@ -128,7 +128,7 @@ struct IndexSubtableFormat1Or3
|
||||||
{
|
{
|
||||||
TRACE_SANITIZE (this);
|
TRACE_SANITIZE (this);
|
||||||
return_trace (c->check_struct (this) &&
|
return_trace (c->check_struct (this) &&
|
||||||
c->check_array (offsetArrayZ, offsetArrayZ[0].static_size, glyph_count + 1));
|
c->check_array (offsetArrayZ, glyph_count + 1));
|
||||||
}
|
}
|
||||||
|
|
||||||
bool get_image_data (unsigned int idx,
|
bool get_image_data (unsigned int idx,
|
||||||
|
@ -240,7 +240,7 @@ struct IndexSubtableArray
|
||||||
inline bool sanitize (hb_sanitize_context_t *c, unsigned int count) const
|
inline bool sanitize (hb_sanitize_context_t *c, unsigned int count) const
|
||||||
{
|
{
|
||||||
TRACE_SANITIZE (this);
|
TRACE_SANITIZE (this);
|
||||||
if (unlikely (!c->check_array (&indexSubtablesZ, indexSubtablesZ[0].static_size, count)))
|
if (unlikely (!c->check_array (indexSubtablesZ, count)))
|
||||||
return_trace (false);
|
return_trace (false);
|
||||||
for (unsigned int i = 0; i < count; i++)
|
for (unsigned int i = 0; i < count; i++)
|
||||||
if (unlikely (!indexSubtablesZ[i].sanitize (c, this)))
|
if (unlikely (!indexSubtablesZ[i].sanitize (c, this)))
|
||||||
|
|
|
@ -208,7 +208,7 @@ struct KernSubTableWrapper
|
||||||
TRACE_SANITIZE (this);
|
TRACE_SANITIZE (this);
|
||||||
return_trace (c->check_struct (thiz()) &&
|
return_trace (c->check_struct (thiz()) &&
|
||||||
thiz()->length >= T::min_size &&
|
thiz()->length >= T::min_size &&
|
||||||
c->check_array (thiz(), 1, thiz()->length) &&
|
c->check_array (thiz(), thiz()->length, 1) &&
|
||||||
thiz()->subtable.sanitize (c, thiz()->format));
|
thiz()->subtable.sanitize (c, thiz()->format));
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
|
@ -1542,7 +1542,7 @@ struct VarData
|
||||||
regionIndices.sanitize(c) &&
|
regionIndices.sanitize(c) &&
|
||||||
shortCount <= regionIndices.len &&
|
shortCount <= regionIndices.len &&
|
||||||
c->check_array (&StructAfter<HBUINT8> (regionIndices),
|
c->check_array (&StructAfter<HBUINT8> (regionIndices),
|
||||||
get_row_size (), itemCount));
|
itemCount, get_row_size ()));
|
||||||
}
|
}
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
|
|
@ -199,7 +199,7 @@ struct ValueFormat : HBUINT16
|
||||||
TRACE_SANITIZE (this);
|
TRACE_SANITIZE (this);
|
||||||
unsigned int len = get_len ();
|
unsigned int len = get_len ();
|
||||||
|
|
||||||
if (!c->check_array (values, get_size (), count)) return_trace (false);
|
if (!c->check_array (values, count, get_size ())) return_trace (false);
|
||||||
|
|
||||||
if (!has_device ()) return_trace (true);
|
if (!has_device ()) return_trace (true);
|
||||||
|
|
||||||
|
@ -376,7 +376,7 @@ struct AnchorMatrix
|
||||||
if (!c->check_struct (this)) return_trace (false);
|
if (!c->check_struct (this)) return_trace (false);
|
||||||
if (unlikely (hb_unsigned_mul_overflows (rows, cols))) return_trace (false);
|
if (unlikely (hb_unsigned_mul_overflows (rows, cols))) return_trace (false);
|
||||||
unsigned int count = rows * cols;
|
unsigned int count = rows * cols;
|
||||||
if (!c->check_array (matrixZ, matrixZ[0].static_size, count)) return_trace (false);
|
if (!c->check_array (matrixZ, count)) return_trace (false);
|
||||||
for (unsigned int i = 0; i < count; i++)
|
for (unsigned int i = 0; i < count; i++)
|
||||||
if (!matrixZ[i].sanitize (c, this)) return_trace (false);
|
if (!matrixZ[i].sanitize (c, this)) return_trace (false);
|
||||||
return_trace (true);
|
return_trace (true);
|
||||||
|
@ -698,7 +698,7 @@ struct PairSet
|
||||||
{
|
{
|
||||||
TRACE_SANITIZE (this);
|
TRACE_SANITIZE (this);
|
||||||
if (!(c->check_struct (this)
|
if (!(c->check_struct (this)
|
||||||
&& c->check_array (arrayZ, HBUINT16::static_size * closure->stride, len))) return_trace (false);
|
&& c->check_array (arrayZ, len, HBUINT16::static_size * closure->stride))) return_trace (false);
|
||||||
|
|
||||||
unsigned int count = len;
|
unsigned int count = len;
|
||||||
const PairValueRecord *record = CastP<PairValueRecord> (arrayZ);
|
const PairValueRecord *record = CastP<PairValueRecord> (arrayZ);
|
||||||
|
@ -869,7 +869,7 @@ struct PairPosFormat2
|
||||||
unsigned int stride = len1 + len2;
|
unsigned int stride = len1 + len2;
|
||||||
unsigned int record_size = valueFormat1.get_size () + valueFormat2.get_size ();
|
unsigned int record_size = valueFormat1.get_size () + valueFormat2.get_size ();
|
||||||
unsigned int count = (unsigned int) class1Count * (unsigned int) class2Count;
|
unsigned int count = (unsigned int) class1Count * (unsigned int) class2Count;
|
||||||
return_trace (c->check_array (values, record_size, count) &&
|
return_trace (c->check_array (values, count, record_size) &&
|
||||||
valueFormat1.sanitize_values_stride_unsafe (c, this, &values[0], count, stride) &&
|
valueFormat1.sanitize_values_stride_unsafe (c, this, &values[0], count, stride) &&
|
||||||
valueFormat2.sanitize_values_stride_unsafe (c, this, &values[len1], count, stride));
|
valueFormat2.sanitize_values_stride_unsafe (c, this, &values[len1], count, stride));
|
||||||
}
|
}
|
||||||
|
|
|
@ -1677,11 +1677,11 @@ struct ContextFormat3
|
||||||
if (!c->check_struct (this)) return_trace (false);
|
if (!c->check_struct (this)) return_trace (false);
|
||||||
unsigned int count = glyphCount;
|
unsigned int count = glyphCount;
|
||||||
if (!count) return_trace (false); /* We want to access coverageZ[0] freely. */
|
if (!count) return_trace (false); /* We want to access coverageZ[0] freely. */
|
||||||
if (!c->check_array (coverageZ.arrayZ, coverageZ[0].static_size, count)) return_trace (false);
|
if (!c->check_array (coverageZ.arrayZ, count)) return_trace (false);
|
||||||
for (unsigned int i = 0; i < count; i++)
|
for (unsigned int i = 0; i < count; i++)
|
||||||
if (!coverageZ[i].sanitize (c, this)) return_trace (false);
|
if (!coverageZ[i].sanitize (c, this)) return_trace (false);
|
||||||
const LookupRecord *lookupRecord = &StructAtOffset<LookupRecord> (coverageZ.arrayZ, coverageZ[0].static_size * count);
|
const LookupRecord *lookupRecord = &StructAtOffset<LookupRecord> (coverageZ.arrayZ, coverageZ[0].static_size * count);
|
||||||
return_trace (c->check_array (lookupRecord, lookupRecord[0].static_size, lookupCount));
|
return_trace (c->check_array (lookupRecord, lookupCount));
|
||||||
}
|
}
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
|
|
@ -242,9 +242,7 @@ struct MathKern
|
||||||
{
|
{
|
||||||
TRACE_SANITIZE (this);
|
TRACE_SANITIZE (this);
|
||||||
return_trace (c->check_struct (this) &&
|
return_trace (c->check_struct (this) &&
|
||||||
c->check_array (mathValueRecords,
|
c->check_array (mathValueRecords, 2 * heightCount + 1) &&
|
||||||
mathValueRecords[0].static_size,
|
|
||||||
2 * heightCount + 1) &&
|
|
||||||
sanitize_math_value_records (c));
|
sanitize_math_value_records (c));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -598,9 +596,7 @@ struct MathVariants
|
||||||
return_trace (c->check_struct (this) &&
|
return_trace (c->check_struct (this) &&
|
||||||
vertGlyphCoverage.sanitize (c, this) &&
|
vertGlyphCoverage.sanitize (c, this) &&
|
||||||
horizGlyphCoverage.sanitize (c, this) &&
|
horizGlyphCoverage.sanitize (c, this) &&
|
||||||
c->check_array (glyphConstruction,
|
c->check_array (glyphConstruction, vertGlyphCount + horizGlyphCount) &&
|
||||||
glyphConstruction[0].static_size,
|
|
||||||
vertGlyphCount + horizGlyphCount) &&
|
|
||||||
sanitize_offsets (c));
|
sanitize_offsets (c));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -118,7 +118,7 @@ struct name
|
||||||
TRACE_SANITIZE (this);
|
TRACE_SANITIZE (this);
|
||||||
return_trace (c->check_struct (this) &&
|
return_trace (c->check_struct (this) &&
|
||||||
likely (format == 0 || format == 1) &&
|
likely (format == 0 || format == 1) &&
|
||||||
c->check_array (nameRecord, nameRecord[0].static_size, count) &&
|
c->check_array (nameRecord, count) &&
|
||||||
sanitize_records (c));
|
sanitize_records (c));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -93,6 +93,7 @@ struct SegmentMaps : ArrayOf<AxisValueMap>
|
||||||
(value - arrayZ[i-1].fromCoord) + denom/2) / denom;
|
(value - arrayZ[i-1].fromCoord) + denom/2) / denom;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public:
|
||||||
DEFINE_SIZE_ARRAY (2, arrayZ);
|
DEFINE_SIZE_ARRAY (2, arrayZ);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -105,8 +106,7 @@ struct avar
|
||||||
TRACE_SANITIZE (this);
|
TRACE_SANITIZE (this);
|
||||||
if (unlikely (!(version.sanitize (c) &&
|
if (unlikely (!(version.sanitize (c) &&
|
||||||
version.major == 1 &&
|
version.major == 1 &&
|
||||||
c->check_struct (this),
|
c->check_struct (this))))
|
||||||
c->check_array(axisSegmentMapsZ.arrayZ, sizeof (axisSegmentMapsZ[0]), axisCount))))
|
|
||||||
return_trace (false);
|
return_trace (false);
|
||||||
|
|
||||||
const SegmentMaps *map = axisSegmentMapsZ.arrayZ;
|
const SegmentMaps *map = axisSegmentMapsZ.arrayZ;
|
||||||
|
|
|
@ -46,7 +46,7 @@ struct InstanceRecord
|
||||||
{
|
{
|
||||||
TRACE_SANITIZE (this);
|
TRACE_SANITIZE (this);
|
||||||
return_trace (c->check_struct (this) &&
|
return_trace (c->check_struct (this) &&
|
||||||
c->check_array (coordinatesZ.arrayZ, coordinatesZ[0].static_size, axis_count));
|
c->check_array (coordinatesZ.arrayZ, axis_count));
|
||||||
}
|
}
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
|
|
@ -39,7 +39,7 @@ struct DeltaSetIndexMap
|
||||||
{
|
{
|
||||||
TRACE_SANITIZE (this);
|
TRACE_SANITIZE (this);
|
||||||
return_trace (c->check_struct (this) &&
|
return_trace (c->check_struct (this) &&
|
||||||
c->check_array (mapDataZ.arrayZ, get_width (), mapCount));
|
c->check_array (mapDataZ.arrayZ, mapCount, get_width ()));
|
||||||
}
|
}
|
||||||
|
|
||||||
unsigned int map (unsigned int v) const /* Returns 16.16 outer.inner. */
|
unsigned int map (unsigned int v) const /* Returns 16.16 outer.inner. */
|
||||||
|
|
|
@ -68,7 +68,7 @@ struct MVAR
|
||||||
c->check_struct (this) &&
|
c->check_struct (this) &&
|
||||||
valueRecordSize >= VariationValueRecord::static_size &&
|
valueRecordSize >= VariationValueRecord::static_size &&
|
||||||
varStore.sanitize (c, this) &&
|
varStore.sanitize (c, this) &&
|
||||||
c->check_array (valuesZ.arrayZ, valueRecordSize, valueRecordCount));
|
c->check_array (valuesZ.arrayZ, valueRecordCount, valueRecordSize));
|
||||||
}
|
}
|
||||||
|
|
||||||
inline float get_var (hb_tag_t tag,
|
inline float get_var (hb_tag_t tag,
|
||||||
|
|
Loading…
Reference in New Issue