Nikolay Sivov : dwrite: Limit recursion level for context lookups.
Alexandre Julliard
julliard at winehq.org
Tue Jun 9 15:27:47 CDT 2020
Module: wine
Branch: master
Commit: 3c415128f1f63eb5b1d768b6b1d060c7ff319cb5
URL: https://source.winehq.org/git/wine.git/?a=commit;h=3c415128f1f63eb5b1d768b6b1d060c7ff319cb5
Author: Nikolay Sivov <nsivov at codeweavers.com>
Date: Tue Jun 9 12:14:33 2020 +0300
dwrite: Limit recursion level for context lookups.
Signed-off-by: Nikolay Sivov <nsivov at codeweavers.com>
Signed-off-by: Alexandre Julliard <julliard at winehq.org>
---
dlls/dwrite/dwrite_private.h | 2 ++
dlls/dwrite/opentype.c | 12 ++++++++++--
2 files changed, 12 insertions(+), 2 deletions(-)
diff --git a/dlls/dwrite/dwrite_private.h b/dlls/dwrite/dwrite_private.h
index 3d7884cb57..0bb5455a67 100644
--- a/dlls/dwrite/dwrite_private.h
+++ b/dlls/dwrite/dwrite_private.h
@@ -543,6 +543,8 @@ struct scriptshaping_context
unsigned int cur;
unsigned int glyph_count;
+ unsigned int nesting_level_left;
+
float emsize;
DWRITE_MEASURING_MODE measuring_mode;
float *advances;
diff --git a/dlls/dwrite/opentype.c b/dlls/dwrite/opentype.c
index 8853f3a424..22ae106924 100644
--- a/dlls/dwrite/opentype.c
+++ b/dlls/dwrite/opentype.c
@@ -67,6 +67,9 @@ WINE_DEFAULT_DEBUG_CHANNEL(dwrite);
#define GET_BE_DWORD(x) RtlUlongByteSwap(x)
#endif
+#define GLYPH_CONTEXT_MAX_LENGTH 64
+#define SHAPE_MAX_NESTING_LEVEL 6
+
typedef struct {
CHAR TTCTag[4];
DWORD Version;
@@ -4616,6 +4619,7 @@ void opentype_layout_apply_gpos_features(struct scriptshaping_context *context,
unsigned int i;
BOOL ret;
+ context->nesting_level_left = SHAPE_MAX_NESTING_LEVEL;
context->u.buffer.apply_context_lookup = opentype_layout_apply_gpos_context_lookup;
opentype_layout_collect_lookups(context, script_index, language_index, features, &context->cache->gpos, &lookups);
@@ -4993,8 +4997,6 @@ static BOOL opentype_layout_apply_gsub_lig_substitution(struct scriptshaping_con
return FALSE;
}
-#define GLYPH_CONTEXT_MAX_LENGTH 64
-
static BOOL opentype_layout_context_match_input(const struct match_context *mc, unsigned int count, const UINT16 *input,
unsigned int *end_offset, unsigned int *match_positions)
{
@@ -5081,6 +5083,9 @@ static BOOL opentype_layout_context_apply_lookup(struct scriptshaping_context *c
unsigned int i, j;
int end, delta;
+ if (!context->nesting_level_left)
+ return TRUE;
+
end = context->cur + match_length;
for (i = 0; i < lookup_count; ++i)
@@ -5097,7 +5102,9 @@ static BOOL opentype_layout_context_apply_lookup(struct scriptshaping_context *c
lookup_index = GET_BE_WORD(lookup_records[i+1]);
+ --context->nesting_level_left;
context->u.buffer.apply_context_lookup(context, lookup_index);
+ ++context->nesting_level_left;
delta = context->glyph_count - orig_len;
if (!delta)
@@ -5692,6 +5699,7 @@ void opentype_layout_apply_gsub_features(struct scriptshaping_context *context,
unsigned int i;
BOOL ret;
+ context->nesting_level_left = SHAPE_MAX_NESTING_LEVEL;
context->u.buffer.apply_context_lookup = opentype_layout_apply_gsub_context_lookup;
opentype_layout_collect_lookups(context, script_index, language_index, features, context->table, &lookups);
More information about the wine-cvs
mailing list