curl / Mailing Lists / curl-library / Single Mail

curl-library

Strange behavior of HTTP upload when resuming without seek function

From: Johan Uppman <uppman.johan_at_gmail.com>
Date: Thu, 10 Nov 2016 08:58:16 +0100

Hi

I just recently created a simple function for uploading files to a
HTTP server using libcurl and noticed a strange behavior when I used
the CURLOPT_RESUME_FROM/CURLOPT_RESUME_FROM_LARGE. I will try to
explain the situation and behavior below.

I had a file A which contained "12345678", half of that file was
already present on the server, i.e. the file on the server contained
"1234". When I then resumed the upload libcurl uploaded the right
amount of bytes and they were placed at the correct offset in the file
on the server. But it uploaded the first half of the file, thus
resulting in the file "12341234" on the server.

When I then checked the source of libcurl 7.51.0 I noticed the
following logic in Curl_http() (specifically at line 2163 in
lib/http.c), expressed in pseudecode.

if CURLOPT_SEEKFUNCTION used
  res = seekfunc(file, offset)
  if res == CURL_SEEKFUNC_CANTSEEK
    readuntil(file, offset)
  end if
end if
size_of_read = size - offset

Thus if no seek function is specified libcurl will simply reduce the
number of bytes to read and read them from the beginning of the file.
Should not the proper behavior be to fallback to the "readuntil"
method if not seek function is specified or possible to indicate an
error, not silently go ahead and upload the wrong bytes?

I tried to find any information on why the behavior is like this but
did not, thus I thought it would be best to send a question to this
mailing list. I hope I have not acted wrongly.

Best regards,
Johan Uppman
-------------------------------------------------------------------
List admin: https://cool.haxx.se/list/listinfo/curl-library
Etiquette: https://curl.haxx.se/mail/etiquette.html
Received on 2016-11-10