Fabian Maurer : riched20: Properly handle \0 inside rtf input.

Alexandre Julliard julliard at winehq.org
Sun Mar 3 13:21:30 CST 2019


Module: wine
Branch: oldstable
Commit: 88015ab1bf6e9d437f9de501f059abd1adc03ce5
URL:    https://source.winehq.org/git/wine.git/?a=commit;h=88015ab1bf6e9d437f9de501f059abd1adc03ce5

Author: Fabian Maurer <dark.shadow4 at web.de>
Date:   Fri Nov  9 09:27:52 2018 +0000

riched20: Properly handle \0 inside rtf input.

Wine-Bug: https://bugs.winehq.org/show_bug.cgi?id=43630
Signed-off-by: Fabian Maurer <dark.shadow4 at web.de>
Signed-off-by: Huw Davies <huw at codeweavers.com>
Signed-off-by: Alexandre Julliard <julliard at winehq.org>
(cherry picked from commit 4600169fd4eedcffb1dee3c146cd0b9cd56f619e)
Signed-off-by: Michael Stefaniuc <mstefani at winehq.org>

---

 dlls/riched20/reader.c       |  2 +-
 dlls/riched20/tests/editor.c | 35 +++++++++++++++++++++++++++++++++++
 2 files changed, 36 insertions(+), 1 deletion(-)

diff --git a/dlls/riched20/reader.c b/dlls/riched20/reader.c
index 0310109..384c6a2 100644
--- a/dlls/riched20/reader.c
+++ b/dlls/riched20/reader.c
@@ -109,7 +109,7 @@ int _RTFGetChar(RTF_Info *info)
 	}
 	ch = (unsigned char)stream->buffer[stream->dwUsed++];
 	if (!ch)
-		 return EOF;
+		 return ' ';
 	return ch;
 }
 
diff --git a/dlls/riched20/tests/editor.c b/dlls/riched20/tests/editor.c
index 9bfbf45..1f35d99 100644
--- a/dlls/riched20/tests/editor.c
+++ b/dlls/riched20/tests/editor.c
@@ -5755,6 +5755,30 @@ static DWORD CALLBACK test_EM_STREAMIN_esCallback_UTF8Split(DWORD_PTR dwCookie,
     return 0;
 }
 
+static DWORD CALLBACK test_EM_STREAMIN_null_bytes(DWORD_PTR cookie, BYTE *buf, LONG size, LONG *written)
+{
+    DWORD *phase = (DWORD *)cookie;
+
+    if (*phase == 0)
+    {
+        static const char first[] = "{\\rtf1\\ansi{Th\0is";
+        *written = sizeof(first);
+        memcpy(buf, first, *written);
+    }
+    else if (*phase == 1)
+    {
+        static const char second[] = " is a test}}";
+        *written = sizeof(second);
+        memcpy(buf, second, *written);
+    }
+    else
+        *written = 0;
+
+    ++*phase;
+
+    return 0;
+}
+
 struct StringWithLength {
     int length;
     char *buffer;
@@ -6041,6 +6065,17 @@ static void test_EM_STREAMIN(void)
   result = SendMessageA(hwndRichEdit, WM_GETTEXT, 1024, (LPARAM)buffer);
   ok (!strcmp(buffer, "line1"),
       "EM_STREAMIN: Unexpected text '%s'\n", buffer);
+
+  /* Test 0-bytes inside text */
+  hwndRichEdit = new_richedit_with_style(NULL, 0);
+  phase = 0;
+  es.dwCookie = (DWORD_PTR)&phase;
+  es.dwError = 0;
+  es.pfnCallback = test_EM_STREAMIN_null_bytes;
+  result = SendMessageA(hwndRichEdit, EM_STREAMIN, SF_RTF, (LPARAM)&es);
+  ok(result == 16, "got %ld, expected %d\n", result, 16);
+  result = SendMessageA(hwndRichEdit, WM_GETTEXT, 1024, (LPARAM)buffer);
+  ok (!strcmp(buffer, "Th is  is a test"), "EM_STREAMIN: Unexpected text '%s'\n", buffer);
 }
 
 static void test_EM_StreamIn_Undo(void)




More information about the wine-cvs mailing list