Nikolay Sivov : dwrite: Validate CreateTextFormat() arguments.
Alexandre Julliard
julliard at winehq.org
Mon Jul 18 09:22:34 CDT 2016
Module: wine
Branch: master
Commit: fee64bed4526ffb73fcdc0ba05601ca75a11d44a
URL: http://source.winehq.org/git/wine.git/?a=commit;h=fee64bed4526ffb73fcdc0ba05601ca75a11d44a
Author: Nikolay Sivov <nsivov at codeweavers.com>
Date: Mon Jul 18 13:03:45 2016 +0300
dwrite: Validate CreateTextFormat() arguments.
Signed-off-by: Nikolay Sivov <nsivov at codeweavers.com>
Signed-off-by: Alexandre Julliard <julliard at winehq.org>
---
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);
More information about the wine-cvs
mailing list