Skip to content

ftp: return the error from an invalid range on download - #23524

Closed
Marti2203 wants to merge 1 commit into
curl:masterfrom
Marti2203:ftp-range-error
Closed

Marti2203 wants to merge 1 commit into
curl:masterfrom
Marti2203:ftp-range-error

Conversation

@Marti2203

@Marti2203 Marti2203 commented Oct 21, 2026 •

Copy link
Copy Markdown
Contributor

An invalid range on an FTP download is silently ignored: curl -r 5-3 ftp://host/file -o out exits 0 without transferring anything, while file:// returns 33 (CURLE_RANGE_ERROR) for the same range.

In ftp_do_more(), the error from Curl_range() only skips setting up the RETR, and is then overwritten by the result of ftp_statemach(). The upload branch just above already returns it, so this does the same for downloads.

Test 1449 (range with an integer overflow) has an invalid range, so it now expects 33, and no QUIT; it fails without the fix.

This issue was found by an LLM-Enhanced Static Analysis Engine and verified manually.

@github-actions github-actions Bot added the tests label Oct 21, 2026

@icing icing left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

good catch

Comment thread tests/data/test377 Outdated
FTP retrieve with an invalid byte-range
</name>
<command>
-r 5-3 ftp://%HOSTIP:%FTPPORT/%TESTNUMBER

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there perhaps an existing test case where this one fits in addition?

The CURLE_RANGE_ERROR returned by Curl_range() for a download was only
used to skip setting up the RETR, and was then overwritten by the
result of ftp_statemach(). So an invalid range such as -r 5-3 made curl
exit with 0 without transferring anything, while file:// returns 33 for
the same range. The upload branch already returns the error.

Test 1449, whose range is also invalid, now expects 33.
@Marti2203

Copy link
Copy Markdown
Contributor Author

Thanks, it turns out test 1449 already covers it: its range is invalid too, and with this change it expects 33 (it exits 0 without the fix). So I dropped test 377 and kept only the test 1449 update.

@bagder bagder closed this in b5ca96a Oct 21, 2026
@bagder

bagder commented Oct 21, 2026

Copy link
Copy Markdown
Member

Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Development

Successfully merging this pull request may close these issues.

4 participants