[spotify] Protect against weird artwork data size from libspotify

For some reason libspotify sometimes returns >1GB sizes?
This commit is contained in:
ejurgensen 2017-10-29 00:36:56 +02:00
parent eff9e6ebeb
commit 7b97503f04

View File

@ -1244,12 +1244,13 @@ artwork_get_bh(void *arg, int *retval)
sp_imageformat imageformat; sp_imageformat imageformat;
sp_error err; sp_error err;
const void *data; const void *data;
char *path;
size_t data_size; size_t data_size;
int ret; int ret;
artwork = arg; artwork = arg;
sp_image *image = artwork->image; sp_image *image = artwork->image;
char *path = artwork->path; path = artwork->path;
fptr_sp_image_remove_load_callback(image, artwork_loaded_cb, artwork); fptr_sp_image_remove_load_callback(image, artwork_loaded_cb, artwork);
@ -1273,17 +1274,25 @@ artwork_get_bh(void *arg, int *retval)
goto fail; goto fail;
} }
data_size = 0;
data = fptr_sp_image_data(image, &data_size); data = fptr_sp_image_data(image, &data_size);
if (!data || (data_size == 0)) if (!data)
{ {
DPRINTF(E_LOG, L_SPOTIFY, "Getting artwork failed, no image data from Spotify: %s\n", path); DPRINTF(E_LOG, L_SPOTIFY, "Getting artwork failed, no image data from Spotify: %s\n", path);
goto fail; goto fail;
} }
if ((data_size < 200) || (data_size > 20000000))
{
// Sometimes we get strange data size even though fptr_sp_image_data returns success
DPRINTF(E_LOG, L_SPOTIFY, "Skipping artwork, data size is weird (%zu)\n", data_size);
goto fail;
}
ret = evbuffer_expand(artwork->evbuf, data_size); ret = evbuffer_expand(artwork->evbuf, data_size);
if (ret < 0) if (ret < 0)
{ {
DPRINTF(E_LOG, L_SPOTIFY, "Out of memory for artwork\n"); DPRINTF(E_LOG, L_SPOTIFY, "Out of memory for artwork (data size requested was %zu)\n", data_size);
goto fail; goto fail;
} }