From: Jacek Caban Subject: [PATCH 1/2] urlmon: Correctly handle empty files Message-Id: <4DF0B681.4030108@codeweavers.com> Date: Thu, 09 Jun 2011 14:03:13 +0200 --- dlls/urlmon/protocol.c | 15 ++++++++++++++- 1 files changed, 14 insertions(+), 1 deletions(-) diff --git a/dlls/urlmon/protocol.c b/dlls/urlmon/protocol.c index 326564b..94801ae 100644 --- a/dlls/urlmon/protocol.c +++ b/dlls/urlmon/protocol.c @@ -286,6 +286,7 @@ HRESULT protocol_start(Protocol *protocol, IInternetProtocol *prot, IUri *uri, HRESULT protocol_continue(Protocol *protocol, PROTOCOLDATA *data) { + BOOL is_start; HRESULT hres; if (!data) { @@ -293,6 +294,8 @@ HRESULT protocol_continue(Protocol *protocol, PROTOCOLDATA *data) return S_OK; } + is_start = data->pData == (LPVOID)BINDSTATUS_DOWNLOADINGDATA; + if(!protocol->request) { WARN("Expected request to be non-NULL\n"); return S_OK; @@ -312,7 +315,7 @@ HRESULT protocol_continue(Protocol *protocol, PROTOCOLDATA *data) if(protocol->post_stream) return write_post_stream(protocol); - if(data->pData == (LPVOID)BINDSTATUS_DOWNLOADINGDATA) { + if(is_start) { hres = protocol->vtbl->start_downloading(protocol); if(FAILED(hres)) { protocol_close_connection(protocol); @@ -344,6 +347,16 @@ HRESULT protocol_continue(Protocol *protocol, PROTOCOLDATA *data) protocol->flags &= ~FLAG_REQUEST_COMPLETE; res = InternetQueryDataAvailable(protocol->request, &protocol->available_bytes, 0, 0); if(res) { + if(!protocol->available_bytes) { + if(is_start) { + TRACE("empty file\n"); + all_data_read(protocol); + }else { + WARN("unexpected end of file?\n"); + report_result(protocol, INET_E_DOWNLOAD_FAILURE); + } + return S_OK; + } protocol->flags |= FLAG_REQUEST_COMPLETE; report_data(protocol); }else if(GetLastError() != ERROR_IO_PENDING) {