]> git.ipfire.org Git - thirdparty/curl.git/commitdiff
sendf: getting less data than "max allowed" is okay
authorDaniel Stenberg <daniel@haxx.se>
Fri, 15 Aug 2025 07:23:33 +0000 (09:23 +0200)
committerDaniel Stenberg <daniel@haxx.se>
Fri, 15 Aug 2025 11:35:04 +0000 (13:35 +0200)
Easily triggered when doing an FTP ranged download with the end range
larger than the file size.

A regression since 30de937bda0 (shipped in curl 8.9.0)

Add test 2307 to verify.

Reported-by: kupavcevdenis on github
Fixes #18283
Closes #18295

lib/sendf.c
tests/data/Makefile.am
tests/data/test2307 [new file with mode: 0644]

index 6bd4b1bfbaf4b2ccdf87198f0b0ac6a8a10be3b6..43b30ecc7ff2ad415f1da73ff4630559b1969e17 100644 (file)
@@ -293,9 +293,9 @@ static CURLcode cw_download_write(struct Curl_easy *data,
     }
 
     if((type & CLIENTWRITE_EOS) && !data->req.no_body &&
-       (data->req.maxdownload > data->req.bytecount)) {
+       (data->req.size > data->req.bytecount)) {
       failf(data, "end of response with %" FMT_OFF_T " bytes missing",
-            data->req.maxdownload - data->req.bytecount);
+            data->req.size - data->req.bytecount);
       return CURLE_PARTIAL_FILE;
     }
   }
index 1c0258e17cbee9fd597398fdff81ba3710bdb8bf..184a54e92ef2487debcb0cbf7dd785acd79a1423 100644 (file)
@@ -256,8 +256,8 @@ test2100 test2101 test2102 test2103 test2104 \
 \
 test2200 test2201 test2202 test2203 test2204 test2205 \
 \
-test2300 test2301 test2302 test2303 test2304 test2306 \
-test2308 test2309 \
+test2300 test2301 test2302 test2303 test2304 test2306 test2307 test2308 \
+test2309 \
 \
 test2400 test2401 test2402 test2403 test2404 test2405 test2406 \
 \
diff --git a/tests/data/test2307 b/tests/data/test2307
new file mode 100644 (file)
index 0000000..cbb581a
--- /dev/null
@@ -0,0 +1,60 @@
+<testcase>
+<info>
+<keywords>
+FTP
+EPSV
+RETR
+Range
+</keywords>
+</info>
+# Server-side
+<reply>
+<data>
+0123456789abcdef
+0123456789abcdef
+0123456789abcdef
+0123456789abcdef
+</data>
+<datacheck nonewline="yes">
+0123456789abcdef
+0123456789abcdef
+0123456789abcdef
+012345678
+</datacheck>
+<size>
+64
+</size>
+</reply>
+
+# Client-side
+<client>
+<server>
+ftp
+</server>
+<name>
+FTP retrieve a byte-range with end larger than file
+</name>
+<command>
+-r 4-1000 ftp://%HOSTIP:%FTPPORT/%TESTNUMBER
+</command>
+</client>
+
+# Verify data after the test has been "shot"
+<verify>
+<strip>
+QUIT
+</strip>
+<protocol crlf="yes">
+USER anonymous
+PASS ftp@example.com
+PWD
+EPSV
+TYPE I
+SIZE %TESTNUMBER
+REST 4
+RETR %TESTNUMBER
+ABOR
+QUIT
+</protocol>
+</verify>
+</testcase>