qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
* [Qemu-devel] [PATCH] curl: Operate on zero-length file
@ 2016-06-28 10:37 Tomáš Golembiovský
  2016-06-28 15:37 ` [Qemu-devel] [Qemu-block] " Kevin Wolf
  0 siblings, 1 reply; 2+ messages in thread
From: Tomáš Golembiovský @ 2016-06-28 10:37 UTC (permalink / raw)
  To: qemu-devel; +Cc: qemu-block, qemu-trivial

This is an attempt to fix small bug 1596870.

When creating new disk backed by remote file accessed via HTTPS and the
backing file has zero length, qemu-img terminates with uniformative
error message:

    qemu-img: disk.qcow2: CURL: Error opening file:

While it may not make much sense to operate on empty file, other block
backends (e.g. raw backend for regular files) seem to allow it. This
patch fixes it for the curl backend.

Signed-off-by: Tomáš Golembiovský <tgolembi@redhat.com>
---
 block/curl.c | 14 ++++++++++----
 1 file changed, 10 insertions(+), 4 deletions(-)

diff --git a/block/curl.c b/block/curl.c
index da9f5e8..ee6c5ea 100644
--- a/block/curl.c
+++ b/block/curl.c
@@ -675,11 +675,17 @@ static int curl_open(BlockDriverState *bs, QDict *options, int flags,
     curl_easy_setopt(state->curl, CURLOPT_HEADERDATA, s);
     if (curl_easy_perform(state->curl))
         goto out;
-    curl_easy_getinfo(state->curl, CURLINFO_CONTENT_LENGTH_DOWNLOAD, &d);
-    if (d)
-        s->len = (size_t)d;
-    else if(!s->len)
+    if (curl_easy_getinfo(state->curl, CURLINFO_CONTENT_LENGTH_DOWNLOAD, &d)) {
         goto out;
+    }
+    if (d < 0) {
+        pstrcpy(state->errmsg, CURL_ERROR_SIZE,
+                "Received invalid file length.");
+        goto out;
+    }
+
+    s->len = (size_t)d;
+
     if ((!strncasecmp(s->url, "http://", strlen("http://"))
         || !strncasecmp(s->url, "https://", strlen("https://")))
         && !s->accept_range) {
-- 
2.9.0

^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [Qemu-devel] [Qemu-block] [PATCH] curl: Operate on zero-length file
  2016-06-28 10:37 [Qemu-devel] [PATCH] curl: Operate on zero-length file Tomáš Golembiovský
@ 2016-06-28 15:37 ` Kevin Wolf
  0 siblings, 0 replies; 2+ messages in thread
From: Kevin Wolf @ 2016-06-28 15:37 UTC (permalink / raw)
  To: Tomáš Golembiovský; +Cc: qemu-devel, qemu-trivial, qemu-block

Am 28.06.2016 um 12:37 hat Tomáš Golembiovský geschrieben:
> This is an attempt to fix small bug 1596870.
> 
> When creating new disk backed by remote file accessed via HTTPS and the
> backing file has zero length, qemu-img terminates with uniformative
> error message:
> 
>     qemu-img: disk.qcow2: CURL: Error opening file:
> 
> While it may not make much sense to operate on empty file, other block
> backends (e.g. raw backend for regular files) seem to allow it. This
> patch fixes it for the curl backend.
> 
> Signed-off-by: Tomáš Golembiovský <tgolembi@redhat.com>
> ---
>  block/curl.c | 14 ++++++++++----
>  1 file changed, 10 insertions(+), 4 deletions(-)
> 
> diff --git a/block/curl.c b/block/curl.c
> index da9f5e8..ee6c5ea 100644
> --- a/block/curl.c
> +++ b/block/curl.c
> @@ -675,11 +675,17 @@ static int curl_open(BlockDriverState *bs, QDict *options, int flags,
>      curl_easy_setopt(state->curl, CURLOPT_HEADERDATA, s);
>      if (curl_easy_perform(state->curl))
>          goto out;
> -    curl_easy_getinfo(state->curl, CURLINFO_CONTENT_LENGTH_DOWNLOAD, &d);
> -    if (d)
> -        s->len = (size_t)d;
> -    else if(!s->len)
> +    if (curl_easy_getinfo(state->curl, CURLINFO_CONTENT_LENGTH_DOWNLOAD, &d)) {
>          goto out;
> +    }
> +    if (d < 0) {
> +        pstrcpy(state->errmsg, CURL_ERROR_SIZE,
> +                "Received invalid file length.");
> +        goto out;
> +    }

Actually, it seems that d == -1 means that there is no information about
the file length, so maybe the error message could be a bit more precise.


A possible problem with the patch is that curl changed its behaviour in
version 7.19.4. Before this version, it used to return 0 for a missing
length, so we can't distinguish these cases on older versions. It's
probably more common not to have the file length than having a
zero-length file.

Do we care about older versions? Commit 8a8f584 suggests that we did
three years ago, it added an #if for a feature added in 7.19.4. Not sure
if we do any more. RHEL 6 seems to be new enough.

But if we do care, I guess we could do a similar #if that enables your
code for newer curl versions and keeps erroring out for older versions.

Any opinions on whether we still care about curl versions that old?

> +    s->len = (size_t)d;
> +
>      if ((!strncasecmp(s->url, "http://", strlen("http://"))
>          || !strncasecmp(s->url, "https://", strlen("https://")))
>          && !s->accept_range) {

Kevin

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2016-06-28 15:37 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2016-06-28 10:37 [Qemu-devel] [PATCH] curl: Operate on zero-length file Tomáš Golembiovský
2016-06-28 15:37 ` [Qemu-devel] [Qemu-block] " Kevin Wolf

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).