summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFlorent Viard <fviard@lacie.com>2017-08-28 17:35:48 +0200
committerFlorent Viard <fviard@lacie.com>2017-08-28 17:35:48 +0200
commit318fe2957a8abb89b322f71dd6b47ba1ac8c8e2a (patch)
tree4295944818098ed9695f3207aa1b3f00527be705
parent1e8283d095bec6e7819281bdddc4cd2419670aa0 (diff)
downloadlibgphoto2-318fe2957a8abb89b322f71dd6b47ba1ac8c8e2a.tar.gz
More fixes for support 64bit getpartialobject for Android in read_file_func
-rw-r--r--camlibs/ptp2/library.c54
-rw-r--r--libgphoto2/gphoto2-camera.c2
-rw-r--r--libgphoto2/gphoto2-filesys.c4
3 files changed, 35 insertions, 25 deletions
diff --git a/camlibs/ptp2/library.c b/camlibs/ptp2/library.c
index 1be24fcbf..a3f4f55f9 100644
--- a/camlibs/ptp2/library.c
+++ b/camlibs/ptp2/library.c
@@ -6584,25 +6584,29 @@ read_file_func (CameraFilesystem *fs, const char *folder, const char *filename,
*/
uint32_t oid;
uint32_t storage;
- uint64_t xsize;
- uint32_t offset = offset64, size = *size64;
+ uint64_t obj_size;
+ uint32_t offset32 = offset64, size32 = *size64;
PTPObject *ob;
SET_CONTEXT_P(params, context);
- C_PARAMS_MSG (*size64 >= 0xffffffff, "size exceeds 32bit");
- /*
- C_PARAMS_MSG (offset64 + *size64 <= 0xffffffff, "offset + size exceeds 32bit");
- */
+ C_PARAMS_MSG (*size64 <= 0xffffffff, "size exceeds 32bit");
C_PARAMS_MSG (strcmp (folder, "/special"), "file not found");
- if ( !ptp_operation_issupported(params, PTP_OC_GetPartialObject) &&
- !( (params->deviceinfo.VendorExtensionID == PTP_VENDOR_MTP) &&
- ptp_operation_issupported(params, PTP_OC_ANDROID_GetPartialObject64)
- )
- )
- return GP_ERROR_NOT_SUPPORTED;
+ if (!ptp_operation_issupported(params, PTP_OC_GetPartialObject) &&
+ !( (params->deviceinfo.VendorExtensionID == PTP_VENDOR_MTP) &&
+ ptp_operation_issupported(params, PTP_OC_ANDROID_GetPartialObject64)
+ )
+ )
+ return GP_ERROR_NOT_SUPPORTED;
+
+ if (!( (params->deviceinfo.VendorExtensionID == PTP_VENDOR_MTP) &&
+ ptp_operation_issupported(params, PTP_OC_ANDROID_GetPartialObject64))
+ && (offset64 > 0xffffffff) ) {
+ GP_LOG_E ("Invalid parameters: offset exceeds 32 bits but the device doesn't support GetPartialObject64.");
+ return GP_ERROR_NOT_SUPPORTED;
+ }
/* compute storage ID value from folder patch */
folder_to_storage(folder,storage);
@@ -6613,10 +6617,10 @@ read_file_func (CameraFilesystem *fs, const char *folder, const char *filename,
gp_context_error (context, _("File '%s/%s' does not exist."), folder, filename);
return GP_ERROR_BAD_PARAMETERS;
}
- GP_LOG_D ("Reading %u bytes from file '%s' at offset %u.", size, filename, offset);
+ GP_LOG_D ("Reading %u bytes from file '%s' at offset %lu.", size32, filename, offset64);
switch (type) {
default:
- return (GP_ERROR_NOT_SUPPORTED);
+ return GP_ERROR_NOT_SUPPORTED;
case GP_FILE_TYPE_NORMAL: {
uint16_t ret;
unsigned char *xdata;
@@ -6640,25 +6644,29 @@ read_file_func (CameraFilesystem *fs, const char *folder, const char *filename,
(ob->oi.ObjectFormat == PTP_OFC_MTP_AbstractAudioVideoPlaylist))
return (GP_ERROR_NOT_SUPPORTED);
- xsize = ob->oi.ObjectCompressedSize;
- if (!xsize)
+ obj_size = ob->oi.ObjectCompressedSize;
+ if (!obj_size)
return GP_ERROR_NOT_SUPPORTED;
- if (size + offset64 > xsize)
- size = xsize - offset64;
+ if (offset64 >= obj_size) {
+ *size64 = 0;
+ return GP_OK;
+ } else if (size32 + offset64 > obj_size) {
+ size32 = obj_size - offset64;
+ }
- if ( (params->deviceinfo.VendorExtensionID == PTP_VENDOR_MTP) &&
+ if ((params->deviceinfo.VendorExtensionID == PTP_VENDOR_MTP) &&
ptp_operation_issupported(params, PTP_OC_ANDROID_GetPartialObject64)
) {
- ret = ptp_android_getpartialobject64(params, oid, offset64, size, &xdata, &size);
+ ret = ptp_android_getpartialobject64(params, oid, offset64, size32, &xdata, &size32);
} else {
- ret = ptp_getpartialobject(params, oid, offset, size, &xdata, &size);
+ ret = ptp_getpartialobject(params, oid, offset32, size32, &xdata, &size32);
}
if (ret == PTP_ERROR_CANCEL)
return GP_ERROR_CANCEL;
C_PTP_REP (ret);
- *size64 = size;
- memcpy (buf, xdata, size);
+ *size64 = size32;
+ memcpy (buf, xdata, size32);
free (xdata);
/* clear the "new" flag on Canons */
if ( (params->deviceinfo.VendorExtensionID == PTP_VENDOR_CANON) &&
diff --git a/libgphoto2/gphoto2-camera.c b/libgphoto2/gphoto2-camera.c
index cdc0a9ae4..5a1cabdc0 100644
--- a/libgphoto2/gphoto2-camera.c
+++ b/libgphoto2/gphoto2-camera.c
@@ -1705,7 +1705,7 @@ gp_camera_file_get (Camera *camera, const char *folder, const char *file,
* @param type the #CameraFileType
* @param offset the offset into the camera file
* @param data the buffer receiving the data
- * @param size the size to be read and that was read
+ * @param size the size to be read and that was read. (Note: size should not exceed 32 bits)
* @param context a #GPContext
* @return a gphoto2 error code
*
diff --git a/libgphoto2/gphoto2-filesys.c b/libgphoto2/gphoto2-filesys.c
index 4d64550e8..5d364a133 100644
--- a/libgphoto2/gphoto2-filesys.c
+++ b/libgphoto2/gphoto2-filesys.c
@@ -1780,8 +1780,10 @@ gp_filesystem_read_file (CameraFilesystem *fs, const char *folder,
offset, buf, size, fs->data, context);
if (r == GP_OK)
return r;
+ } else {
+ return GP_ERROR_NOT_SUPPORTED;
}
- return GP_ERROR_NOT_SUPPORTED;
+ return r;
/* fallback code */
CR (gp_file_new (&file));
CR (gp_filesystem_get_file (fs, folder, filename, type,