Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[colr] Make rejecting paint-graph cycles in COLRv1 a compile-time option #272

Merged
merged 1 commit into from
Feb 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,10 @@ if get_option('synthesize-gvar')
conf.set('OTS_SYNTHESIZE_MISSING_GVAR', 1)
endif

if get_option('colr-cycle-check')
conf.set('OTS_COLR_CYCLE_CHECK', 1)
endif

freetype = dependency('freetype2', required: false)
if freetype.found()
conf.set('HAVE_FREETYPE', 1)
Expand Down
1 change: 1 addition & 0 deletions meson_options.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
option('colr-cycle-check', type : 'boolean', value : true, description : 'Reject fonts with cycles in COLRv1 paint graph')
option('graphite', type : 'boolean', value : true, description : 'Sanitize Graphite tables')
option('synthesize-gvar', type : 'boolean', value : true, description : 'Synthesize an empty gvar if fvar is present')
option('fuzzer_ldflags', type: 'string', description : 'Extra LDFLAGS used during linking of fuzzing binaries')
13 changes: 13 additions & 0 deletions src/colr.cc
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,15 @@ bool ParsePaintColrLayers(const ots::Font* font,
colrState& state)
{
if (setContains(state.visited, data)) {
#ifdef OTS_COLR_CYCLE_CHECK
// A cycle would imply an infinite loop during painting, unless the renderer
// detects and breaks it. To be safe, reject the table.
return OTS_FAILURE_MSG("Cycle detected in PaintColrLayers");
#else
// Just issue a warning and return (as we've already checked this subgraph).
OTS_WARNING("Cycle detected in COLRv1 glyph paint graph (PaintColrLayers)\n");
return true;
#endif
}
state.visited.insert(data);

Expand Down Expand Up @@ -393,7 +401,12 @@ bool ParsePaintColrGlyph(const ots::Font* font,
colrState& state)
{
if (setContains(state.visited, data)) {
#ifdef OTS_COLR_CYCLE_CHECK
return OTS_FAILURE_MSG("Cycle detected in PaintColrGlyph");
#else
OTS_WARNING("Cycle detected in COLRv1 glyph paint graph (PaintColrGlyph)\n");
return true;
#endif
}
state.visited.insert(data);

Expand Down