in getpartialobject, take care that we do not read over the
end of the file. this requires fetching the filesize, but
we likely have cached that info already.
diff --git a/src/libmtp.c b/src/libmtp.c
index 432f6b1..f9157ff 100644
--- a/src/libmtp.c
+++ b/src/libmtp.c
@@ -8987,8 +8987,19 @@
uint64_t offset, uint32_t maxbytes,
unsigned char **data, unsigned int *size)
{
- PTPParams *params = (PTPParams *) device->params;
- uint16_t ret;
+ PTPParams *params = (PTPParams *) device->params;
+ uint16_t ret;
+ LIBMTP_file_t *mtpfile = LIBMTP_Get_Filemetadata(device, id);
+
+ /* Some devices do not like reading over the end and hang instead of progressing */
+ if (offset >= mtpfile->filesize) {
+ *size = 0;
+ LIBMTP_destroy_file_t (mtpfile);
+ return 0;
+ }
+ if (offset + maxbytes > mtpfile->filesize) {
+ maxbytes = mtpfile->filesize - offset;
+ }
if (!ptp_operation_issupported(params, PTP_OC_ANDROID_GetPartialObject64)) {
if (!ptp_operation_issupported(params, PTP_OC_GetPartialObject)) {