[sfnt] Handle fonts without layer list in 'COLR' v1. 'COLR' v1 fonts do not necessarily need to have a layer list; for this reason, 'fontTools' recently started generating fonts in a way that drops the layer list if there are no layers in it. This results in the layer list offset becoming zero, which FreeType treated as an invalid table. Fix that and handle the case for layer list offset being 0. This slightly changes how we need to calculate the starting offset for paints. * src/sfnt/ttcolr.c (tt_face_load_colr): Handle case of layer list offset being zero without outright rejecting table.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76
diff --git a/ChangeLog b/ChangeLog
index a1de346..eccf4a1 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,18 @@
+2021-06-30 Dominik Röttsches <drott@chromium.org>
+
+ [sfnt] Handle fonts without layer list in 'COLR' v1.
+
+ 'COLR' v1 fonts do not necessarily need to have a layer list; for
+ this reason, 'fontTools' recently started generating fonts in a way
+ that drops the layer list if there are no layers in it. This
+ results in the layer list offset becoming zero, which FreeType
+ treated as an invalid table. Fix that and handle the case for layer
+ list offset being 0. This slightly changes how we need to calculate
+ the starting offset for paints.
+
+ * src/sfnt/ttcolr.c (tt_face_load_colr): Handle case of layer list
+ offset being zero without outright rejecting table.
+
2021-06-30 Alexei Podtelezhnikov <apodtele@gmail.com>
* src/raster/ftraster.c (Render_Single_Pass): Simplify `band_stack'.
diff --git a/src/sfnt/ttcolr.c b/src/sfnt/ttcolr.c
index 1e297ac..34accdd 100644
--- a/src/sfnt/ttcolr.c
+++ b/src/sfnt/ttcolr.c
@@ -186,24 +186,35 @@
layer_offset_v1 = FT_NEXT_ULONG( p );
- if ( !layer_offset_v1 || layer_offset_v1 >= table_size )
+ if ( layer_offset_v1 >= table_size )
goto InvalidTable;
- p1 = (FT_Byte*)( table + layer_offset_v1 );
- num_layers_v1 = FT_PEEK_ULONG( p1 );
+ if ( layer_offset_v1 )
+ {
+ p1 = (FT_Byte*)( table + layer_offset_v1 );
+ num_layers_v1 = FT_PEEK_ULONG( p1 );
- if ( num_layers_v1 * LAYER_V1_LIST_PAINT_OFFSET_SIZE >
- table_size - layer_offset_v1 )
- goto InvalidTable;
+ if ( num_layers_v1 * LAYER_V1_LIST_PAINT_OFFSET_SIZE >
+ table_size - layer_offset_v1 )
+ goto InvalidTable;
- colr->num_layers_v1 = num_layers_v1;
- colr->layers_v1 = p1;
+ colr->num_layers_v1 = num_layers_v1;
+ colr->layers_v1 = p1;
- colr->paints_start_v1 =
- FT_MIN( colr->base_glyphs_v1 +
- colr->num_base_glyphs_v1 * BASE_GLYPH_PAINT_RECORD_SIZE,
- colr->layers_v1 +
- colr->num_layers_v1 * LAYER_V1_LIST_PAINT_OFFSET_SIZE );
+ colr->paints_start_v1 =
+ FT_MIN( colr->base_glyphs_v1 +
+ colr->num_base_glyphs_v1 * BASE_GLYPH_PAINT_RECORD_SIZE,
+ colr->layers_v1 +
+ colr->num_layers_v1 * LAYER_V1_LIST_PAINT_OFFSET_SIZE );
+ }
+ else
+ {
+ colr->num_layers_v1 = 0;
+ colr->layers_v1 = 0;
+ colr->paints_start_v1 =
+ colr->base_glyphs_v1 +
+ colr->num_base_glyphs_v1 * BASE_GLYPH_PAINT_RECORD_SIZE;
+ }
}
colr->base_glyphs = (FT_Byte*)( table + base_glyph_offset );