From 66917c61d6e61c97941ff0f1d09b3855fcb1fd9e Mon Sep 17 00:00:00 2001 From: Jacek Caban Date: Thu, 9 Jun 2011 14:03:13 +0200 Subject: [PATCH] urlmon: Correctly handle empty files. --- dlls/urlmon/protocol.c | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/dlls/urlmon/protocol.c b/dlls/urlmon/protocol.c index 326564b907c..94801aefcec 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) {