From 7be11594799c7b37ae2a285ce36f68bcdaec9d21 Mon Sep 17 00:00:00 2001 From: Nikolay Sivov Date: Sat, 6 Jun 2015 19:05:00 +0300 Subject: [PATCH] dwrite: Validate per-range attribute values. --- dlls/dwrite/layout.c | 9 +++++++++ dlls/dwrite/tests/layout.c | 28 +++++++++++++++++++++++++++- 2 files changed, 36 insertions(+), 1 deletion(-) diff --git a/dlls/dwrite/layout.c b/dlls/dwrite/layout.c index af0e6f3e3b0..150e34bea91 100644 --- a/dlls/dwrite/layout.c +++ b/dlls/dwrite/layout.c @@ -1937,6 +1937,9 @@ static HRESULT WINAPI dwritetextlayout_SetFontStyle(IDWriteTextLayout2 *iface, D TRACE("(%p)->(%d %s)\n", This, style, debugstr_range(&range)); + if ((UINT32)style > DWRITE_FONT_STYLE_ITALIC) + return E_INVALIDARG; + value.range = range; value.u.style = style; return set_layout_range_attr(This, LAYOUT_RANGE_ATTR_STYLE, &value); @@ -1949,6 +1952,9 @@ static HRESULT WINAPI dwritetextlayout_SetFontStretch(IDWriteTextLayout2 *iface, TRACE("(%p)->(%d %s)\n", This, stretch, debugstr_range(&range)); + if (stretch == DWRITE_FONT_STRETCH_UNDEFINED || (UINT32)stretch > DWRITE_FONT_STRETCH_ULTRA_EXPANDED) + return E_INVALIDARG; + value.range = range; value.u.stretch = stretch; return set_layout_range_attr(This, LAYOUT_RANGE_ATTR_STRETCH, &value); @@ -1961,6 +1967,9 @@ static HRESULT WINAPI dwritetextlayout_SetFontSize(IDWriteTextLayout2 *iface, FL TRACE("(%p)->(%.2f %s)\n", This, size, debugstr_range(&range)); + if (size <= 0.0) + return E_INVALIDARG; + value.range = range; value.u.fontsize = size; return set_layout_range_attr(This, LAYOUT_RANGE_ATTR_FONTSIZE, &value); diff --git a/dlls/dwrite/tests/layout.c b/dlls/dwrite/tests/layout.c index 4c76f501e83..a740c4f09f2 100644 --- a/dlls/dwrite/tests/layout.c +++ b/dlls/dwrite/tests/layout.c @@ -1832,6 +1832,15 @@ static void test_SetFontSize(void) hr = IDWriteFactory_CreateTextLayout(factory, strW, 4, format, 1000.0, 1000.0, &layout); ok(hr == S_OK, "got 0x%08x\n", hr); + /* negative/zero size */ + r.startPosition = 1; + r.length = 1; + hr = IDWriteTextLayout_SetFontSize(layout, -15.0, r); + ok(hr == E_INVALIDARG, "got 0x%08x\n", hr); + + hr = IDWriteTextLayout_SetFontSize(layout, 0.0, r); + ok(hr == E_INVALIDARG, "got 0x%08x\n", hr); + r.startPosition = 1; r.length = 0; size = 0.0; @@ -1909,6 +1918,12 @@ static void test_SetFontFamilyName(void) hr = IDWriteFactory_CreateTextLayout(factory, strW, 4, format, 1000.0, 1000.0, &layout); ok(hr == S_OK, "got 0x%08x\n", hr); + /* NULL name */ + r.startPosition = 1; + r.length = 1; + hr = IDWriteTextLayout_SetFontFamilyName(layout, NULL, r); + ok(hr == E_INVALIDARG, "got 0x%08x\n", hr); + r.startPosition = 1; r.length = 0; nameW[0] = 0; @@ -1961,6 +1976,12 @@ static void test_SetFontStyle(void) hr = IDWriteFactory_CreateTextLayout(factory, strW, 4, format, 1000.0, 1000.0, &layout); ok(hr == S_OK, "got 0x%08x\n", hr); + /* invalid style value */ + r.startPosition = 1; + r.length = 1; + hr = IDWriteTextLayout_SetFontStyle(layout, DWRITE_FONT_STYLE_ITALIC+1, r); + ok(hr == E_INVALIDARG, "got 0x%08x\n", hr); + r.startPosition = 1; r.length = 0; hr = IDWriteTextLayout_GetFontStyle(layout, 0, &style, &r); @@ -2036,6 +2057,12 @@ static void test_SetFontStretch(void) hr = IDWriteFactory_CreateTextLayout(factory, strW, 4, format, 1000.0, 1000.0, &layout); ok(hr == S_OK, "got 0x%08x\n", hr); + /* invalid stretch value */ + r.startPosition = 1; + r.length = 1; + hr = IDWriteTextLayout_SetFontStretch(layout, DWRITE_FONT_STRETCH_ULTRA_EXPANDED+1, r); + ok(hr == E_INVALIDARG, "got 0x%08x\n", hr); + r.startPosition = 1; r.length = 0; stretch = DWRITE_FONT_STRETCH_UNDEFINED; @@ -2093,7 +2120,6 @@ static void test_SetFontStretch(void) r.startPosition = 0; r.length = 2; hr = IDWriteTextLayout_SetFontStretch(layout, DWRITE_FONT_STRETCH_UNDEFINED, r); -todo_wine ok(hr == E_INVALIDARG, "got 0x%08x\n", hr); IDWriteTextLayout_Release(layout); -- 2.11.4.GIT