[PATCH 2/2] dwrite: Validate CreateTextFormat() arguments
Nikolay Sivov
nsivov at codeweavers.com
Mon Jul 18 05:03:45 CDT 2016
Signed-off-by: Nikolay Sivov <nsivov at codeweavers.com>
---
dlls/dwrite/layout.c | 8 ++++++++
dlls/dwrite/tests/layout.c | 29 +++++++++++++++++++++++++++++
2 files changed, 37 insertions(+)
diff --git a/dlls/dwrite/layout.c b/dlls/dwrite/layout.c
index 48d0816..d292764 100644
--- a/dlls/dwrite/layout.c
+++ b/dlls/dwrite/layout.c
@@ -5133,6 +5133,14 @@ HRESULT create_textformat(const WCHAR *family_name, IDWriteFontCollection *colle
*format = NULL;
+ if (size <= 0.0f)
+ return E_INVALIDARG;
+
+ if (((UINT32)weight > DWRITE_FONT_WEIGHT_ULTRA_BLACK) ||
+ ((UINT32)stretch > DWRITE_FONT_STRETCH_ULTRA_EXPANDED) ||
+ ((UINT32)style > DWRITE_FONT_STYLE_ITALIC))
+ return E_INVALIDARG;
+
This = heap_alloc(sizeof(struct dwrite_textformat));
if (!This) return E_OUTOFMEMORY;
diff --git a/dlls/dwrite/tests/layout.c b/dlls/dwrite/tests/layout.c
index ddc63d6..689b3b4 100644
--- a/dlls/dwrite/tests/layout.c
+++ b/dlls/dwrite/tests/layout.c
@@ -933,6 +933,7 @@ static void test_CreateGdiCompatibleTextLayout(void)
static void test_CreateTextFormat(void)
{
+ static const WCHAR emptyW[] = {0};
IDWriteFontCollection *collection, *syscoll;
DWRITE_PARAGRAPH_ALIGNMENT paralign;
DWRITE_READING_DIRECTION readdir;
@@ -949,6 +950,34 @@ static void test_CreateTextFormat(void)
factory = create_factory();
+ /* zero/negative font size */
+ hr = IDWriteFactory_CreateTextFormat(factory, tahomaW, NULL, DWRITE_FONT_WEIGHT_NORMAL, DWRITE_FONT_STYLE_NORMAL,
+ DWRITE_FONT_STRETCH_NORMAL, 0.0f, enusW, &format);
+ ok(hr == E_INVALIDARG, "got 0x%08x\n", hr);
+
+ hr = IDWriteFactory_CreateTextFormat(factory, tahomaW, NULL, DWRITE_FONT_WEIGHT_NORMAL, DWRITE_FONT_STYLE_NORMAL,
+ DWRITE_FONT_STRETCH_NORMAL, -10.0f, enusW, &format);
+ ok(hr == E_INVALIDARG, "got 0x%08x\n", hr);
+
+ /* invalid font properties */
+ hr = IDWriteFactory_CreateTextFormat(factory, tahomaW, NULL, 1000, DWRITE_FONT_STYLE_NORMAL,
+ DWRITE_FONT_STRETCH_NORMAL, 10.0f, enusW, &format);
+ ok(hr == E_INVALIDARG, "got 0x%08x\n", hr);
+
+ hr = IDWriteFactory_CreateTextFormat(factory, tahomaW, NULL, DWRITE_FONT_WEIGHT_NORMAL, DWRITE_FONT_STYLE_ITALIC + 1,
+ DWRITE_FONT_STRETCH_NORMAL, 10.0f, enusW, &format);
+ ok(hr == E_INVALIDARG, "got 0x%08x\n", hr);
+
+ hr = IDWriteFactory_CreateTextFormat(factory, tahomaW, NULL, DWRITE_FONT_WEIGHT_NORMAL, DWRITE_FONT_STYLE_ITALIC,
+ 10, 10.0f, enusW, &format);
+ ok(hr == E_INVALIDARG, "got 0x%08x\n", hr);
+
+ /* empty family name */
+ hr = IDWriteFactory_CreateTextFormat(factory, emptyW, NULL, DWRITE_FONT_WEIGHT_NORMAL, DWRITE_FONT_STYLE_NORMAL,
+ DWRITE_FONT_STRETCH_NORMAL, 10.0f, enusW, &format);
+ ok(hr == S_OK, "got 0x%08x\n", hr);
+ IDWriteTextFormat_Release(format);
+
hr = IDWriteFactory_CreateTextFormat(factory, tahomaW, NULL, DWRITE_FONT_WEIGHT_NORMAL, DWRITE_FONT_STYLE_NORMAL,
DWRITE_FONT_STRETCH_NORMAL, 10.0, enusW, &format);
ok(hr == S_OK, "got 0x%08x\n", hr);
--
2.8.1
More information about the wine-patches
mailing list