diff options
author | Jerry Zhang <zhangjerry@google.com> | 2017-06-15 12:42:13 -0700 |
---|---|---|
committer | Jerry Zhang <zhangjerry@google.com> | 2017-06-15 14:40:03 -0700 |
commit | 6c016415c6bd986413088a330595786d7d3d358c (patch) | |
tree | 5451c867ef898d36760d56a1a8f2d48822ceea5a /src/libusb-glue.c | |
parent | c58b24651a56989fdf39b42202c77e72749e8bab (diff) | |
download | libmtp-6c016415c6bd986413088a330595786d7d3d358c.tar.gz |
Fix 4G file transfer on 32 bit.android-o-mr1-iot-release-smart-display-r9android-o-mr1-iot-release-smart-display-r8android-o-mr1-iot-release-smart-display-r5android-o-mr1-iot-release-smart-display-r40.1Jandroid-o-mr1-iot-release-smart-display-r4android-o-mr1-iot-release-smart-display-r39android-o-mr1-iot-release-smart-display-r30android-o-mr1-iot-release-smart-display-r3android-o-mr1-iot-release-smart-display-r22android-o-mr1-iot-release-smart-display-r14android-o-mr1-iot-release-smart-clock-r6android-o-mr1-iot-release-smart-clock-r2android-o-mr1-iot-release-smart-clock-fsiandroid-o-mr1-iot-release-smart-clock-fcsandroid-o-mr1-iot-release-cube_r2android-o-mr1-iot-release-cube-fsiandroid-o-mr1-iot-release-cube-fcsandroid-o-mr1-iot-release-1.0.8android-o-mr1-iot-release-1.0.7android-o-mr1-iot-release-1.0.5android-o-mr1-iot-release-1.0.4android-o-mr1-iot-release-1.0.3android-o-mr1-iot-release-1.0.2android-o-mr1-iot-release-1.0.14android-o-mr1-iot-release-1.0.13android-o-mr1-iot-release-1.0.12android-o-mr1-iot-release-1.0.10android-o-mr1-iot-release-1.0.1android-o-mr1-iot-release-1.0.0android-o-mr1-iot-preview-8android-o-mr1-iot-preview-7android-o-mr1-iot-preview-6oreo-mr1-iot-releaseoreo-mr1-devoreo-mr1-1.2-iot-releaseo-mr1-iot-preview-8o-mr1-iot-preview-7o-mr1-iot-preview-6
ptp_usb_senddata will store file size in a uint64_t,
but ptp_write_func casts this down to an unsigned long,
which is 32 bits on i386.
To fix, break up transfers into pieces less than
ULONG_MAX rounded down by packet size.
Diffstat (limited to 'src/libusb-glue.c')
-rw-r--r-- | src/libusb-glue.c | 8 |
1 files changed, 7 insertions, 1 deletions
diff --git a/src/libusb-glue.c b/src/libusb-glue.c index 722a591..0079b08 100644 --- a/src/libusb-glue.c +++ b/src/libusb-glue.c @@ -1202,6 +1202,10 @@ ptp_usb_senddata (PTPParams* params, PTPContainer* ptp, PTPUSBBulkContainer usbdata; uint64_t bytes_left_to_transfer; PTPDataHandler memhandler; + unsigned long packet_size; + PTP_USB *ptp_usb = (PTP_USB *) params->data; + + packet_size = ptp_usb->inep_maxpacket; LIBMTP_USB_DEBUG("SEND DATA PHASE\n"); @@ -1242,7 +1246,9 @@ ptp_usb_senddata (PTPParams* params, PTPContainer* ptp, bytes_left_to_transfer = size-datawlen; ret = PTP_RC_OK; while(bytes_left_to_transfer > 0) { - ret = ptp_write_func (bytes_left_to_transfer, handler, params->data, &written); + int max_long_transfer = ULONG_MAX + 1 - packet_size; + ret = ptp_write_func (bytes_left_to_transfer > max_long_transfer ? max_long_transfer : bytes_left_to_transfer, + handler, params->data, &written); if (ret != PTP_RC_OK) break; if (written == 0) { |