From 06e8d06be7e4c68516008a15c20719c86d6953a4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gabriel=20Iv=C4=83ncescu?= Date: Wed, 13 Jul 2022 20:07:32 +0300 Subject: [PATCH] mshtml: Respect LOAD_CALL_CONTENT_SNIFFERS when using detected mime type. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Gabriel Ivăncescu --- dlls/mshtml/navigate.c | 3 ++- dlls/mshtml/tests/events.js | 10 ++++++++++ dlls/mshtml/tests/img.png | Bin 0 -> 74 bytes dlls/mshtml/tests/rsrc.rc | 3 +++ dlls/mshtml/tests/script.c | 13 +++++++++++-- 5 files changed, 26 insertions(+), 3 deletions(-) create mode 100644 dlls/mshtml/tests/img.png diff --git a/dlls/mshtml/navigate.c b/dlls/mshtml/navigate.c index 5f736dbf07c..6f684630cd6 100644 --- a/dlls/mshtml/navigate.c +++ b/dlls/mshtml/navigate.c @@ -1670,7 +1670,8 @@ static HRESULT nsChannelBSC_on_progress(BSCallback *bsc, ULONG status_code, LPCW This->nschannel = NULL; } - if(!This->nschannel) + if(!This->nschannel || + (This->nschannel->content_type && !(This->nschannel->load_flags & LOAD_CALL_CONTENT_SNIFFERS))) return S_OK; heap_free(This->nschannel->content_type); diff --git a/dlls/mshtml/tests/events.js b/dlls/mshtml/tests/events.js index 75893cac204..e67bf07d210 100644 --- a/dlls/mshtml/tests/events.js +++ b/dlls/mshtml/tests/events.js @@ -797,6 +797,16 @@ async_test("detached_img_error_event", function() { img.src = "about:blank"; }); +async_test("img_wrong_content_type", function() { + var img = new Image(); + img.onload = function() { + ok(img.width === 2, "width = " + img.width); + ok(img.height === 2, "height = " + img.height); + next_test(); + } + img.src = "img.png?content-type=image/jpeg"; +}); + async_test("message event", function() { var listener_called = false; diff --git a/dlls/mshtml/tests/img.png b/dlls/mshtml/tests/img.png new file mode 100644 index 0000000000000000000000000000000000000000..86b6c0c259b7d2a6e06911a77839117a63a3b929 GIT binary patch literal 74 zcmeAS@N?(olHy`uVBq!ia0vp^Od!kwBL7~QRScvAJzX3_DsCnJ;Ai1+U{LzU%wT+r V^|#o`9e06}44$rjF6*2UngBP`5}yD7 literal 0 HcmV?d00001 diff --git a/dlls/mshtml/tests/rsrc.rc b/dlls/mshtml/tests/rsrc.rc index 61e6c940b90..25c81246b26 100644 --- a/dlls/mshtml/tests/rsrc.rc +++ b/dlls/mshtml/tests/rsrc.rc @@ -80,3 +80,6 @@ res.html test "jstest.html" /* @makedep: jstest.html */ dir/dir2/res.html test "jstest.html" + +/* @makedep: img.png */ +img.png PNG "img.png" diff --git a/dlls/mshtml/tests/script.c b/dlls/mshtml/tests/script.c index e3688242715..a92d18fb454 100644 --- a/dlls/mshtml/tests/script.c +++ b/dlls/mshtml/tests/script.c @@ -3043,6 +3043,7 @@ typedef struct { IInternetProtocolSink *sink; BINDINFO bind_info; + BSTR content_type; IStream *stream; char *data; ULONG size; @@ -3068,6 +3069,7 @@ static void report_data(ProtocolHandler *This) IServiceProvider *service_provider; IHttpNegotiate *http_negotiate; WCHAR *addl_headers = NULL; + WCHAR headers_buf[128]; BSTR headers, url; HRESULT hres; @@ -3091,7 +3093,10 @@ static void report_data(ProtocolHandler *This) CoTaskMemFree(addl_headers); - headers = SysAllocString(L"HTTP/1.1 200 OK\r\n\r\n"); + if(This->content_type) + swprintf(headers_buf, ARRAY_SIZE(headers_buf), L"HTTP/1.1 200 OK\r\nContent-Type: %s\r\n", This->content_type); + + headers = SysAllocString(This->content_type ? headers_buf : L"HTTP/1.1 200 OK\r\n\r\n"); hres = IHttpNegotiate_OnResponse(http_negotiate, 200, headers, NULL, NULL); ok(hres == S_OK, "OnResponse failed: %08lx\n", hres); SysFreeString(headers); @@ -3250,6 +3255,7 @@ static ULONG WINAPI Protocol_Release(IInternetProtocolEx *iface) if(This->uri) IUri_Release(This->uri); ReleaseBindInfo(&This->bind_info); + SysFreeString(This->content_type); HeapFree(GetProcessHeap(), 0, This); } @@ -3397,7 +3403,8 @@ static HRESULT WINAPI ProtocolEx_StartEx(IInternetProtocolEx *iface, IUri *uri, This->data = empty_data; This->size = strlen(This->data); }else { - src = FindResourceW(NULL, *path == '/' ? path+1 : path, (const WCHAR*)RT_HTML); + const WCHAR *type = (SysStringLen(path) > 4 && !wcsicmp(path + SysStringLen(path) - 4, L".png")) ? L"PNG" : (const WCHAR*)RT_HTML; + src = FindResourceW(NULL, *path == '/' ? path+1 : path, type); if(src) { This->size = SizeofResource(NULL, src); This->data = LoadResource(NULL, src); @@ -3424,6 +3431,8 @@ static HRESULT WINAPI ProtocolEx_StartEx(IInternetProtocolEx *iface, IUri *uri, if(SUCCEEDED(hres)) { if(!lstrcmpW(query, L"?delay")) This->delay = 1000; + else if(!wcsncmp(query, L"?content-type=", sizeof("?content-type=")-1)) + This->content_type = SysAllocString(query + sizeof("?content-type=")-1); SysFreeString(query); }