mtp: Fix crashes on NULL StorageDescriptions
The MTP spec section 5.2.2.7 allows StorageDescription
to be
an empty string.
libmtp
currently translates this to
char * StorageDescription = NULL
instead of ""
in ptp_unpack_SI()
via ptp_unpack_string()
.
(I'm not sure if it's good that it does that, to be followed up on separately. Edit: https://github.com/libmtp/libmtp/issues/67)
create_storage_name()
until now returned
g_strdup(storage->StorageDescription)
, which returns NULL
if NULL
is
given, and thus get_storage_info()
would eventually call
char *storage_name = NULL = create_storage_name(storage);
g_file_info_set_name (info, storage_name = NULL);
g_file_info_set_display_name (info, storage_name = NULL);
resulting in assertion failures in gvfsd
:
g_file_info_set_name: assertion 'name != NULL' failed
g_file_info_set_display_name: assertion 'display_name != NULL' failed
as well as crashes in file managers like Thunar:
g_file_get_child: assertion 'name != NULL' failed
and warnings in Nautilus like:
Got GFileInfo with NULL name in mtp://Ricoh_Company__Ltd._RICOH_THETA_V_00165759/, ignoring. This shouldn't happen unless the gvfs backend is broken.
This commit fixes it by adding a contract to create_storage_name()
that it will never represent empty strings as NULL.
I've tested this on top of 1.44.1 on NixOS 20.09; it fixes the crashes of all programs mentioned above.
This fix is sponsored by my company benaco.com, so that users of the Ricoh Theta V and Theta Z1 cameras can use MTP instead of PTP, thus avoiding that > 4 GiB video files will be silently cut off.