From 00110a639aea03250476a32349fd9093d54b2c46 Mon Sep 17 00:00:00 2001 From: Přemysl Eric Janouch Date: Sat, 20 May 2023 23:46:39 +0200 Subject: Avoid use of NULL picture data pointers The sanitizer would scream, and LibRaw would rather confusingly return I/O errors. --- fiv-thumbnail.c | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/fiv-thumbnail.c b/fiv-thumbnail.c index c552073..0933951 100644 --- a/fiv-thumbnail.c +++ b/fiv-thumbnail.c @@ -281,6 +281,12 @@ fiv_thumbnail_extract(GFile *target, FivThumbnailSize max_size, GError **error) // TODO(p): Implement our own thumbnail extractors. set_error(error, "unsupported file"); #else // HAVE_LIBRAW + // In this case, g_mapped_file_get_contents() returns NULL, causing issues. + if (!g_mapped_file_get_length(mf)) { + set_error(error, "empty file"); + goto fail; + } + libraw_data_t *iprc = libraw_init( LIBRAW_OPIONS_NO_MEMERR_CALLBACK | LIBRAW_OPIONS_NO_DATAERR_CALLBACK); if (!iprc) { @@ -535,7 +541,13 @@ fiv_thumbnail_produce(GFile *target, FivThumbnailSize max_size, GError **error) return produce_fallback(target, max_size, error); } + // In this case, g_mapped_file_get_bytes() has NULL data, causing issues. gsize filesize = g_mapped_file_get_length(mf); + if (!filesize) { + set_error(error, "empty file"); + return NULL; + } + gboolean color_managed = FALSE; cairo_surface_t *surface = render(target, g_mapped_file_get_bytes(mf), &color_managed, error); -- cgit v1.2.3-70-g09d2