oleaut32: Fix OleLoadPicturePath behavior on wrong path (bug 14710)

Nikolay Sivov bunglehead at gmail.com
Sun Dec 7 04:27:47 CST 2008


Changelog:
    - fix OleLoadPicturePath behavior on wrong path
    - some cosmetic changes on module and test (spaces, tabs, ..)

>From af340b56e642c1fcb14f3b5bd4c37c51662ccf7e Mon Sep 17 00:00:00 2001
From: Nikolay Sivov <bunglehead at gmail.com>
Date: Sun, 7 Dec 2008 13:25:02 +0300
Subject:  Fix OleLoadPicturePath behavior on wrong path (bug 14710)

---
 dlls/oleaut32/olepicture.c       |   68 +++++++++++++++++++-------------------
 dlls/oleaut32/tests/olepicture.c |   65 +++++++++++++++++++++++-------------
 2 files changed, 76 insertions(+), 57 deletions(-)

diff --git a/dlls/oleaut32/olepicture.c b/dlls/oleaut32/olepicture.c
index 498ee53..2cbd3ed 100644
--- a/dlls/oleaut32/olepicture.c
+++ b/dlls/oleaut32/olepicture.c
@@ -2718,65 +2718,65 @@ HRESULT WINAPI OleLoadPicturePath( LPOLESTR szURLorPath, LPUNKNOWN punkCaller,
 
   if (!ppvRet) return E_POINTER;
 
-  if (strncmpW(szURLorPath, file, 7) == 0) {	    
+  if (strncmpW(szURLorPath, file, 7) == 0) {
       szURLorPath += 7;
   
       hFile = CreateFileW(szURLorPath, GENERIC_READ, 0, NULL, OPEN_EXISTING,
 				   0, NULL);
-      if (hFile == INVALID_HANDLE_VALUE)
-	  return E_UNEXPECTED;
+      if (hFile == INVALID_HANDLE_VALUE){
+          *ppvRet = NULL;
+          return INET_E_RESOURCE_NOT_FOUND;
+      }
 
       dwFileSize = GetFileSize(hFile, NULL);
-      if (dwFileSize != INVALID_FILE_SIZE )
+      if (dwFileSize != INVALID_FILE_SIZE)
       {
-	  hGlobal = GlobalAlloc(GMEM_FIXED,dwFileSize);
-	  if ( hGlobal)
-	  {
-	      bRead = ReadFile(hFile, hGlobal, dwFileSize, &dwBytesRead, NULL);
-	      if (!bRead)
-	      {
-		  GlobalFree(hGlobal);
-		  hGlobal = 0;
+          hGlobal = GlobalAlloc(GMEM_FIXED,dwFileSize);
+          if ( hGlobal){
+              bRead = ReadFile(hFile, hGlobal, dwFileSize, &dwBytesRead, NULL);
+              if (!bRead){
+                  GlobalFree(hGlobal);
+                  hGlobal = 0;
+              }
 	      }
-	  }
       }
       CloseHandle(hFile);
-      
+
       if (!hGlobal)
-	  return E_UNEXPECTED;
+         return E_UNEXPECTED;
 
       hRes = CreateStreamOnHGlobal(hGlobal, TRUE, &stream);
-      if (FAILED(hRes)) 
-      {
-	  GlobalFree(hGlobal);
-	  return hRes;
+      if (FAILED(hRes)){
+          GlobalFree(hGlobal);
+          return hRes;
       }
   } else {
       IMoniker *pmnk;
       IBindCtx *pbc;
 
       hRes = CreateBindCtx(0, &pbc);
-      if (SUCCEEDED(hRes)) 
-      {
-	  hRes = CreateURLMoniker(NULL, szURLorPath, &pmnk);
-	  if (SUCCEEDED(hRes))
-	  {	         
-	      hRes = IMoniker_BindToStorage(pmnk, pbc, NULL, &IID_IStream, (LPVOID*)&stream);
-	      IMoniker_Release(pmnk);
-	  }
-	  IBindCtx_Release(pbc);
+      if (SUCCEEDED(hRes)){
+          hRes = CreateURLMoniker(NULL, szURLorPath, &pmnk);
+
+          if (SUCCEEDED(hRes)){
+	          hRes = IMoniker_BindToStorage(pmnk, pbc, NULL, &IID_IStream, (LPVOID*)&stream);
+              IMoniker_Release(pmnk);
+          }
+          IBindCtx_Release(pbc);
+      }
+      if (FAILED(hRes)){
+          *ppvRet = NULL;
+          return INET_E_UNKNOWN_PROTOCOL;
       }
-      if (FAILED(hRes))
-	  return hRes;
   }
 
-  hRes = CoCreateInstance(&CLSID_StdPicture, punkCaller, CLSCTX_INPROC_SERVER, 
+  hRes = CoCreateInstance(&CLSID_StdPicture, punkCaller, CLSCTX_INPROC_SERVER,
 		   &IID_IPicture, (LPVOID*)&ipicture);
   if (hRes != S_OK) {
       IStream_Release(stream);
       return hRes;
   }
-  
+
   hRes = IPicture_QueryInterface(ipicture, &IID_IPersistStream, (LPVOID*)&pStream);
   if (hRes) {
       IStream_Release(stream);
@@ -2784,7 +2784,7 @@ HRESULT WINAPI OleLoadPicturePath( LPOLESTR szURLorPath, LPUNKNOWN punkCaller,
       return hRes;
   }
 
-  hRes = IPersistStream_Load(pStream, stream); 
+  hRes = IPersistStream_Load(pStream, stream);
   IPersistStream_Release(pStream);
   IStream_Release(stream);
 
@@ -2796,7 +2796,7 @@ HRESULT WINAPI OleLoadPicturePath( LPOLESTR szURLorPath, LPUNKNOWN punkCaller,
   hRes = IPicture_QueryInterface(ipicture,riid,ppvRet);
   if (hRes)
       ERR("Failed to get interface %s from IPicture.\n",debugstr_guid(riid));
-  
+
   IPicture_Release(ipicture);
   return hRes;
 }
diff --git a/dlls/oleaut32/tests/olepicture.c b/dlls/oleaut32/tests/olepicture.c
index f81c419..e8b8183 100644
--- a/dlls/oleaut32/tests/olepicture.c
+++ b/dlls/oleaut32/tests/olepicture.c
@@ -587,32 +587,51 @@ static void test_enhmetafile(void)
     GlobalFree(hglob);
 }
 
+static void test_OleLoadPicturePath(void)
+{
+    IPicture *pic;
+    static WCHAR path[] = {'N','O','.','B','M','P',0};
+    static WCHAR fpath[]= {'f','i','l','e',':','/','/','N','O','.','B','M','P',0};
+    HRESULT res;
+
+    pic = (IPicture*)0xdeadbeef;
+    res = OleLoadPicturePath(path, NULL, 0, 0, &IID_IPicture, (LPVOID*)&pic);
+    ole_expect(res, INET_E_UNKNOWN_PROTOCOL);
+    ok(!pic, "NULL pointer expected on wrong path\n");
+
+    pic = (IPicture*)0xdeadbeef;
+    res = OleLoadPicturePath(fpath, NULL, 0, 0, &IID_IPicture, (LPVOID*)&pic);
+    ole_expect(res, INET_E_RESOURCE_NOT_FOUND);
+    ok(!pic, "NULL pointer expected on wrong path\n");
+}
+
 START_TEST(olepicture)
 {
-	hOleaut32 = GetModuleHandleA("oleaut32.dll");
-	pOleLoadPicture = (void*)GetProcAddress(hOleaut32, "OleLoadPicture");
-	pOleCreatePictureIndirect = (void*)GetProcAddress(hOleaut32, "OleCreatePictureIndirect");
-	if (!pOleLoadPicture)
-	{
-	    skip("OleLoadPicture is not available\n");
-	    return;
-	}
+    hOleaut32 = GetModuleHandleA("oleaut32.dll");
+    pOleLoadPicture = (void*)GetProcAddress(hOleaut32, "OleLoadPicture");
+    pOleCreatePictureIndirect = (void*)GetProcAddress(hOleaut32, "OleCreatePictureIndirect");
+    if (!pOleLoadPicture)
+    {
+        skip("OleLoadPicture is not available\n");
+        return;
+    }
 
-	/* Test regular 1x1 pixel images of gif, jpg, bmp type */
-        test_pic(gifimage, sizeof(gifimage));
-	test_pic(jpgimage, sizeof(jpgimage));
-	test_pic(bmpimage, sizeof(bmpimage));
-        test_pic(gif4pixel, sizeof(gif4pixel));
-	/* FIXME: No PNG support yet in Wine or in older Windows... */
-	if (0) test_pic(pngimage, sizeof(pngimage));
-	test_empty_image();
-	test_empty_image_2();
-        test_apm();
-        test_metafile();
-        test_enhmetafile();
-
-	test_Invoke();
-        test_OleCreatePictureIndirect();
+    /* Test regular 1x1 pixel images of gif, jpg, bmp type */
+    test_pic(gifimage, sizeof(gifimage));
+    test_pic(jpgimage, sizeof(jpgimage));
+    test_pic(bmpimage, sizeof(bmpimage));
+    test_pic(gif4pixel, sizeof(gif4pixel));
+    /* FIXME: No PNG support yet in Wine or in older Windows... */
+    if (0) test_pic(pngimage, sizeof(pngimage));
+    test_empty_image();
+    test_empty_image_2();
+    test_apm();
+    test_metafile();
+    test_enhmetafile();
+
+    test_Invoke();
+    test_OleCreatePictureIndirect();
+    test_OleLoadPicturePath();
 }
 
 
-- 
1.4.4.4






More information about the wine-patches mailing list