Nikolay Sivov : dwrite/layout: Fail to create layouts with negative size.

Alexandre Julliard julliard at winehq.org
Wed Jan 20 16:58:42 CST 2021


Module: wine
Branch: master
Commit: 9ec274083f273a3a6d7415599d097c206204e1ac
URL:    https://source.winehq.org/git/wine.git/?a=commit;h=9ec274083f273a3a6d7415599d097c206204e1ac

Author: Nikolay Sivov <nsivov at codeweavers.com>
Date:   Wed Jan 20 08:44:12 2021 +0300

dwrite/layout: Fail to create layouts with negative size.

Signed-off-by: Nikolay Sivov <nsivov at codeweavers.com>
Signed-off-by: Alexandre Julliard <julliard at winehq.org>

---

 dlls/dwrite/layout.c       |  3 +++
 dlls/dwrite/tests/layout.c | 37 +++++++++++++++++++++++++++++++++++--
 2 files changed, 38 insertions(+), 2 deletions(-)

diff --git a/dlls/dwrite/layout.c b/dlls/dwrite/layout.c
index 58aa05abd44..0b5bad80339 100644
--- a/dlls/dwrite/layout.c
+++ b/dlls/dwrite/layout.c
@@ -5207,6 +5207,9 @@ HRESULT create_textlayout(const struct textlayout_desc *desc, IDWriteTextLayout
 
     *layout = NULL;
 
+    if (desc->max_width < 0.0f || desc->max_height < 0.0f)
+        return E_INVALIDARG;
+
     if (!desc->format || !desc->string)
         return E_INVALIDARG;
 
diff --git a/dlls/dwrite/tests/layout.c b/dlls/dwrite/tests/layout.c
index 7d950a0626c..52f17820e5e 100644
--- a/dlls/dwrite/tests/layout.c
+++ b/dlls/dwrite/tests/layout.c
@@ -908,7 +908,7 @@ static void test_CreateTextLayout(void)
     factory = create_factory();
 
     layout = (void*)0xdeadbeef;
-    hr = IDWriteFactory_CreateTextLayout(factory, NULL, 0, NULL, 0.0, 0.0, &layout);
+    hr = IDWriteFactory_CreateTextLayout(factory, NULL, 0, NULL, 0.0f, 0.0f, &layout);
     ok(hr == E_INVALIDARG, "got 0x%08x\n", hr);
     ok(layout == NULL, "got %p\n", layout);
 
@@ -941,6 +941,21 @@ static void test_CreateTextLayout(void)
     ok(hr == E_INVALIDARG, "got 0x%08x\n", hr);
     ok(layout == NULL, "got %p\n", layout);
 
+    layout = (void *)0xdeadbeef;
+    hr = IDWriteFactory_CreateTextLayout(factory, L"string", 6, format, -100.0f, 100.0f, &layout);
+    ok(hr == E_INVALIDARG, "Unexpected hr %#x.\n", hr);
+    ok(layout == NULL, "Unexpected pointer %p.\n", layout);
+
+    layout = (void *)0xdeadbeef;
+    hr = IDWriteFactory_CreateTextLayout(factory, L"string", 6, format, 100.0f, -100.0f, &layout);
+    ok(hr == E_INVALIDARG, "Unexpected hr %#x.\n", hr);
+    ok(layout == NULL, "Unexpected pointer %p.\n", layout);
+
+    layout = (void *)0xdeadbeef;
+    hr = IDWriteFactory_CreateTextLayout(factory, L"string", 6, format, -100.0f, -100.0f, &layout);
+    ok(hr == E_INVALIDARG, "Unexpected hr %#x.\n", hr);
+    ok(layout == NULL, "Unexpected pointer %p.\n", layout);
+
     hr = IDWriteFactory_CreateTextLayout(factory, L"string", 0, format, 0.0f, 0.0f, &layout);
     ok(hr == S_OK, "Failed to create text layout, hr %#x.\n", hr);
     IDWriteTextLayout_Release(layout);
@@ -1031,7 +1046,7 @@ static void test_CreateGdiCompatibleTextLayout(void)
     factory = create_factory();
 
     layout = (void*)0xdeadbeef;
-    hr = IDWriteFactory_CreateGdiCompatibleTextLayout(factory, NULL, 0, NULL, 0.0, 0.0, 0.0, NULL, FALSE, &layout);
+    hr = IDWriteFactory_CreateGdiCompatibleTextLayout(factory, NULL, 0, NULL, 0.0f, 0.0f, 0.0f, NULL, FALSE, &layout);
     ok(hr == E_INVALIDARG, "got 0x%08x\n", hr);
     ok(layout == NULL, "got %p\n", layout);
 
@@ -1070,6 +1085,24 @@ static void test_CreateGdiCompatibleTextLayout(void)
     ok(hr == E_INVALIDARG, "got 0x%08x\n", hr);
     ok(layout == NULL, "got %p\n", layout);
 
+    layout = (void *)0xdeadbeef;
+    hr = IDWriteFactory_CreateGdiCompatibleTextLayout(factory, L"string", 6, format, -100.0f, 100.0f, 1.0f,
+            NULL, FALSE, &layout);
+    ok(hr == E_INVALIDARG, "Unexpected hr %#x.\n", hr);
+    ok(layout == NULL, "Unexpected pointer %p.\n", layout);
+
+    layout = (void *)0xdeadbeef;
+    hr = IDWriteFactory_CreateGdiCompatibleTextLayout(factory, L"string", 6, format, 100.0f, -100.0f, 1.0f,
+            NULL, FALSE, &layout);
+    ok(hr == E_INVALIDARG, "Unexpected hr %#x.\n", hr);
+    ok(layout == NULL, "Unexpected pointer %p.\n", layout);
+
+    layout = (void *)0xdeadbeef;
+    hr = IDWriteFactory_CreateGdiCompatibleTextLayout(factory, L"string", 6, format, -100.0f, -100.0f, 1.0f,
+            NULL, FALSE, &layout);
+    ok(hr == E_INVALIDARG, "Unexpected hr %#x.\n", hr);
+    ok(layout == NULL, "Unexpected pointer %p.\n", layout);
+
     hr = IDWriteFactory_CreateGdiCompatibleTextLayout(factory, L"string", 6, format, 100.0f, 100.0f, 1.0f, NULL,
             FALSE, &layout);
     ok(hr == S_OK, "Failed to create text layout, hr %#x.\n", hr);




More information about the wine-cvs mailing list