[PATCH 2/2] webservices: Don't advance reader on binary encoding if element hasn't been found.

Connor McAdams cmcadams at codeweavers.com
Mon Apr 18 12:13:09 CDT 2022


If we haven't found a valid element in read_element_bin, don't advance
the reader position.

Signed-off-by: Connor McAdams <cmcadams at codeweavers.com>
---

This fixes an issue where a nested structure with a final field that is
optional advances the reader past the end element of the nested
structure when checking for the optional element, which then causes the
reader to fail to find the end element for the nested structure.

---
 dlls/webservices/reader.c       |  3 ++-
 dlls/webservices/tests/reader.c | 15 ++++++---------
 2 files changed, 8 insertions(+), 10 deletions(-)

diff --git a/dlls/webservices/reader.c b/dlls/webservices/reader.c
index 7da0c8335ea..933c921097f 100644
--- a/dlls/webservices/reader.c
+++ b/dlls/webservices/reader.c
@@ -2068,8 +2068,9 @@ static HRESULT read_element_bin( struct reader *reader )
     unsigned char type;
     HRESULT hr;
 
-    if ((hr = read_byte( reader, &type )) != S_OK) return hr;
+    if ((hr = read_peek( reader, &type, 1 )) != S_OK) return hr;
     if (!is_element_type( type )) return WS_E_INVALID_FORMAT;
+    read_skip( reader, 1 );
 
     if (!(elem = alloc_element_pair())) return E_OUTOFMEMORY;
     node = (struct node *)elem;
diff --git a/dlls/webservices/tests/reader.c b/dlls/webservices/tests/reader.c
index 1a2cd1fe420..f62697b9662 100644
--- a/dlls/webservices/tests/reader.c
+++ b/dlls/webservices/tests/reader.c
@@ -5764,15 +5764,12 @@ static void test_binary_encoding(void)
 
     hr = WsReadType( reader, WS_ELEMENT_TYPE_MAPPING, WS_STRUCT_TYPE, &s,
                      WS_READ_REQUIRED_POINTER, heap, &test_struct, sizeof(test_struct), NULL );
-    todo_wine ok( hr == S_OK, "got %#lx\n", hr );
-    if (SUCCEEDED(hr))
-    {
-        ok( test_struct->a == 1, "got %d\n", test_struct->a );
-        ok( !!test_struct->s, "s is not set\n" );
-        ok( test_struct->s->s_a == 1, "got %d\n", test_struct->s->s_a );
-        ok( test_struct->s->s_b == 0, "got %d\n", test_struct->s->s_b );
-        ok( test_struct->b == 1, "got %d\n", test_struct->b );
-    }
+    ok( hr == S_OK, "got %#lx\n", hr );
+    ok( test_struct->a == 1, "got %d\n", test_struct->a );
+    ok( !!test_struct->s, "s is not set\n" );
+    ok( test_struct->s->s_a == 1, "got %d\n", test_struct->s->s_a );
+    ok( test_struct->s->s_b == 0, "got %d\n", test_struct->s->s_b );
+    ok( test_struct->b == 1, "got %d\n", test_struct->b );
 
     WsFreeHeap( heap );
     WsFreeReader( reader );
-- 
2.25.1




More information about the wine-devel mailing list