Ticket #100 (closed defect)

Opened 8 years ago

Last modified 8 years ago

libssh2_scp_send() does not support files >4GB

Reported by: p82420 Owned by: bagder
Priority: normal Milestone:
Component: API Version:
Keywords: Cc: p82420, bagder
Blocked By: Blocks:

Description

Note: I'm using Solaris 9/10, libssh2 1.1

The 4th parameter of libssh2_scp_send() is of type size_t. With the ILP32 (default) model, size_t is 32-bits wide. That makes impossible to transfer files larger than 4GB. I've not tested the LP64 model (accessible with -m64 on Sun Studio and probably gcc), but that should work. Nevertheless, size_t is not the appropriate C type for file sizes. POSIX uses off_t, which is either long long (-D_FILE_OFFSET_BITS=64 or LP64 model) or long.

See attached patch (I've used the off_t C type, but fill free to use any 64-bit wide type).

Gaëtan

Attachments

patch (1.6 KB) - added by p82420 8 years ago.

Download all attachments as: .zip

Change History

Changed 8 years ago by p82420

comment:1 Changed 8 years ago by bagder

This report seems to confuse matters.

libssh2 supports SCP for files larger than 4GB, but it does not support sending more than 4GB in a single libssh2_scp_send() call on systems where size_t is 32bit. I can't think of any legitimate use-case where you'd want to do this.

libssh2_scp_send() is meant to be called repeatedly over and over with data to send.

comment:2 Changed 8 years ago by p82420

Because I'm doing something like this on files larger than 4GB:

fd = open(path, O_RDONLY);
channel = libssh2_scp_send(session, path, mode, size);
while (more data to write) {

len = read(fd, buf, len);
libssh2_channel_write(channel, buf, len);

}
libssh2_channel_free(channel);

Calling libssh2_scp_send() twice with the same parameters overwrites the target file.

comment:3 Changed 8 years ago by bagder

Sorry. Quite clearly I am the confused part here. Yes, this API does not allow any larger size than size_t can hold.

We should fix this but:

A - we can't change this function without breaking the ABI so I would prefer we added a new function that has a 64bit argument for the file size.

B - Using off_t in an API is very error-prone and I really think we need to find another type to use. I would appreciate if we could take that as a discussion on the mailing list to see what others have to say about how this is best made.

comment:4 Changed 8 years ago by bagder

This issue is now added to the TODO document, so hopefully someone will work on this at some point.

comment:5 Changed 8 years ago by sf-robot

This Tracker item was closed automatically by the system. It was
previously set to a Pending status, and the original submitter
did not respond within 14 days (the time period specified by
the administrator of this Tracker).

Note: See TracTickets for help on using tickets.