Hi, On Sat, Mar 12, 2011 at 2:46 PM, Albert Astals Cid <[email protected]> wrote: > A Dimecres, 9 de març de 2011, Hib Eris va escriure: >> Hi Albert, >> >> On Wed, Mar 9, 2011 at 1:00 AM, Albert Astals Cid <[email protected]> wrote: >> > A Diumenge, 30 de gener de 2011, Albert Astals Cid va escriure: >> >> I see that in CurlCachedFileLoader::init we do >> >> curl_easy_getinfo(curl, CURLINFO_RESPONSE_CODE, &code); >> >> And then never use code again. Can we just remove that line? >> > >> > Hib? >> >> My aplogies to you for not replying to this earlier, it fell of my to >> do list at some point. I will take a look at it this weekend. Looks >> like as it is now the line could be removed, but the proper fix would >> be to actually do something sane when curl returns an error code. > > I'll be removing the line until you provide a fixed code. > > Albert
Here is a patch. Hib
From d2303355b77d4fd56db861d9b7b86c94530c7681 Mon Sep 17 00:00:00 2001 From: Hib Eris <[email protected]> Date: Sat, 12 Mar 2011 23:17:59 +0100 Subject: [PATCH] Check response code of libcurl call --- poppler/CachedFile.cc | 8 +++++++- poppler/CurlCachedFile.cc | 12 +++++++++--- 2 files changed, 16 insertions(+), 4 deletions(-) diff --git a/poppler/CachedFile.cc b/poppler/CachedFile.cc index f1e49d1..79218e6 100644 --- a/poppler/CachedFile.cc +++ b/poppler/CachedFile.cc @@ -29,7 +29,13 @@ CachedFile::CachedFile(CachedFileLoader *cachedFileLoaderA, GooString *uriA) length = loader->init(uri, this); refCnt = 1; - chunks->resize(length/CachedFileChunkSize + 1); + if (length != ((size_t) -1)) { + chunks->resize(length/CachedFileChunkSize + 1); + } + else { + error(-1, "Failed to initialize file cache for '%s'.", uri->getCString()); + chunks->resize(0); + } } CachedFile::~CachedFile() diff --git a/poppler/CurlCachedFile.cc b/poppler/CurlCachedFile.cc index bd50241..8ddf9a2 100644 --- a/poppler/CurlCachedFile.cc +++ b/poppler/CurlCachedFile.cc @@ -39,6 +39,7 @@ size_t CurlCachedFileLoader::init(GooString *urlA, CachedFile *cachedFileA) { double contentLength = -1; + long code = 0; size_t size; url = urlA; @@ -50,11 +51,16 @@ CurlCachedFileLoader::init(GooString *urlA, CachedFile *cachedFileA) curl_easy_setopt(curl, CURLOPT_NOBODY, 1); curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, &noop_cb); curl_easy_perform(curl); - curl_easy_getinfo(curl, CURLINFO_CONTENT_LENGTH_DOWNLOAD, &contentLength); + curl_easy_getinfo(curl, CURLINFO_RESPONSE_CODE, &code); + if (code) { + curl_easy_getinfo(curl, CURLINFO_CONTENT_LENGTH_DOWNLOAD, &contentLength); + size = contentLength; + } else { + error(-1, "Failed to get size of '%s'.", url->getCString()); + size = -1; + } curl_easy_reset(curl); - size = contentLength; - return size; } -- 1.7.3.4
_______________________________________________ poppler mailing list [email protected] http://lists.freedesktop.org/mailman/listinfo/poppler
