From 9ec274083f273a3a6d7415599d097c206204e1ac Mon Sep 17 00:00:00 2001 From: Nikolay Sivov Date: Wed, 20 Jan 2021 08:44:12 +0300 Subject: [PATCH] dwrite/layout: Fail to create layouts with negative size. Signed-off-by: Nikolay Sivov Signed-off-by: Alexandre Julliard --- 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);