Skip to content

SCP: server-declared size of UINT64_MAX silently disables download size checks (libssh backend) #23474

Closed

Description

@Nora-Qiu

I did this

The SCP download path in the libssh backend accepts a server-declared file size of 18446744073709551615 (UINT64_MAX). The value survives parsing and ends up as -1 in curl's curl_off_t, which collides with curl's "unknown download size" sentinel. As a result the partial-file check and the excess-data check are both skipped, and curl exits 0 even when the server sends a different amount of data than it declared.

Verified on 8.21.0-DEV and again on current master 5d4eaac8f (2026-10-18, libssh 0.11.2 backend), with a paramiko-based SCP server:

Server declares Server sends Exit code Result
18446744073709551615 100 bytes 0 No CURLE_PARTIAL_FILE, no excess flag (checks skipped)
18446744073709551615 500 bytes 0 Excess detection skipped
200 100 bytes 18 CURLE_PARTIAL_FILE, as expected
100 100 bytes 0 Normal transfer
18446744073709551615, continuous send unlimited 63 --max-filesize still enforced (mitigation works)

The interesting part is the first row: a pipeline that trusts the exit code (backup scripts, mirrors) silently accepts a truncated or short transfer whenever the server declares this size.

Two more things:

  1. The SFTP path validates the declared size (sftp_download_stat() has if(size < 0) checks), but the SCP path does not validate anything. I do not think the asymmetry is intentional, it looks like the SCP path was simply missed.
  2. The libssh2 backend's master branch recently gained a strict parser for the SCP C line (ssh2_scp_parse_c_fields) that rejects anything but digits, which blocks negative and overflowing declarations on that backend. The libssh backend still accepts UINT64_MAX.

Suggested fix: validate the declared size in the SCP path the same way the SFTP path does, before it reaches maxdownload and k->size.

I expected the following

No response

curl/libcurl version

git master 8.23.1-DEV (commit 5d4eaac, 2026-10-17)

operating system

Ubuntu 22.04.5 LTS, x86_64, Linux

Activity

  1. self-assigned this
    on Oct 18, 2026
  2. added a commit that references this issue on Oct 18, 2026
    9ef1a3a
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions