summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGravatar Alexey Yakovenko <wakeroid@gmail.com>2010-05-22 12:12:19 +0200
committerGravatar Alexey Yakovenko <wakeroid@gmail.com>2010-05-22 12:12:19 +0200
commitcacfeb0d9749074f6fd58fb58db3e8dcf7a2a139 (patch)
tree5a6e9f8c4fb6bbd9a7a28d6cd0f846bfafbd6b8a
parentc2ec43487c376f5e44db0b7513675c8788869f95 (diff)
coverart: prevent attempts to load partial files
-rw-r--r--plugins/artwork/albumartorg.c13
-rw-r--r--plugins/artwork/artwork.c4
-rw-r--r--plugins/artwork/lastfm.c13
-rw-r--r--plugins/gtkui/coverart.c15
4 files changed, 33 insertions, 12 deletions
diff --git a/plugins/artwork/albumartorg.c b/plugins/artwork/albumartorg.c
index 18b494a4..d438cf9c 100644
--- a/plugins/artwork/albumartorg.c
+++ b/plugins/artwork/albumartorg.c
@@ -74,9 +74,11 @@ fetch_from_albumart_org (const char *artist, const char *album, const char *dest
}
current_file = fp;
- FILE *out = fopen (dest, "w+b");
+ char temp[PATH_MAX];
+ snprintf (temp, sizeof (temp), "%s.part", dest);
+ FILE *out = fopen (temp, "w+b");
if (!out) {
- trace ("fetch_from_albumart_org: failed to open %s for writing\n", dest);
+ trace ("fetch_from_albumart_org: failed to open %s for writing\n", temp);
current_file = NULL;
deadbeef->fclose (fp);
return -1;
@@ -98,9 +100,16 @@ fetch_from_albumart_org (const char *artist, const char *album, const char *dest
deadbeef->fclose (fp);
if (error) {
+ unlink (temp);
+ return -1;
+ }
+
+ if (rename (temp, dest) != 0) {
+ unlink (temp);
unlink (dest);
return -1;
}
+
return 0;
}
diff --git a/plugins/artwork/artwork.c b/plugins/artwork/artwork.c
index ef2d0e00..4af9658b 100644
--- a/plugins/artwork/artwork.c
+++ b/plugins/artwork/artwork.c
@@ -435,7 +435,7 @@ fetcher_thread (void *none)
char*
get_album_art (const char *fname, const char *artist, const char *album, artwork_callback callback, void *user_data)
{
-// trace ("get_album_art: %s (%s - %s)\n", fname, artist, album);
+ trace ("get_album_art: %s (%s - %s)\n", fname, artist, album);
char path [1024];
if (!album) {
@@ -470,7 +470,7 @@ get_album_art (const char *fname, const char *artist, const char *album, artwork
}
}
-// trace ("found %s in cache\n", path);
+ trace ("found %s in cache\n", path);
return strdup (path);
}
diff --git a/plugins/artwork/lastfm.c b/plugins/artwork/lastfm.c
index 2aed6d7c..bf76ccca 100644
--- a/plugins/artwork/lastfm.c
+++ b/plugins/artwork/lastfm.c
@@ -64,9 +64,11 @@ fetch_from_lastfm (const char *artist, const char *album, const char *dest)
}
current_file = fp;
- FILE *out = fopen (dest, "w+b");
+ char temp[PATH_MAX];
+ snprintf (temp, sizeof (temp), "%s.part", dest);
+ FILE *out = fopen (temp, "w+b");
if (!out) {
- trace ("fetch_from_lastfm: failed to open %s for writing\n", dest);
+ trace ("fetch_from_lastfm: failed to open %s for writing\n", temp);
deadbeef->fclose (fp);
current_file = NULL;
return -1;
@@ -88,8 +90,15 @@ fetch_from_lastfm (const char *artist, const char *album, const char *dest)
deadbeef->fclose (fp);
if (error) {
+ unlink (temp);
+ return -1;
+ }
+
+ if (rename (temp, dest) != 0) {
+ unlink (temp);
unlink (dest);
return -1;
}
+
return 0;
}
diff --git a/plugins/gtkui/coverart.c b/plugins/gtkui/coverart.c
index af6ed4d3..778d83f1 100644
--- a/plugins/gtkui/coverart.c
+++ b/plugins/gtkui/coverart.c
@@ -140,17 +140,18 @@ loading_thread (void *none) {
usleep (500000);
continue;
}
- trace ("loading image %s\n", queue->fname);
- GdkPixbuf *pixbuf = gdk_pixbuf_new_from_file (queue->fname, NULL);
+// GdkPixbuf *pixbuf = gdk_pixbuf_new_from_file (queue->fname, NULL);
+ GError *error;
+ GdkPixbuf *pixbuf = gdk_pixbuf_new_from_file_at_scale (queue->fname, queue->width, queue->width, TRUE, &error);
if (!pixbuf) {
- trace ("GDK failed to load pixbuf from file %s\n", queue->fname);
pixbuf = gdk_pixbuf_new_from_file (DEFAULT_COVER_PATH, NULL);
}
if (!pixbuf) {
// make default empty image
pixbuf = gdk_pixbuf_new (GDK_COLORSPACE_RGB, FALSE, 8, 2, 2);
}
+#if 0
else {
int w, h;
w = gdk_pixbuf_get_width (pixbuf);
@@ -179,6 +180,7 @@ loading_thread (void *none) {
pixbuf = scaled;
}
}
+#endif
if (cache_min != -1) {
deadbeef->mutex_lock (mutex);
cache[cache_min].pixbuf = pixbuf;
@@ -217,9 +219,10 @@ get_pixbuf (const char *fname, int width) {
if (cache[i].pixbuf) {
if (!strcmp (fname, cache[i].fname) && cache[i].width == width) {
gettimeofday (&cache[i].tm, NULL);
- g_object_ref (cache[i].pixbuf);
+ GdkPixbuf *pb = cache[i].pixbuf;
+ g_object_ref (pb);
deadbeef->mutex_unlock (mutex);
- return cache[i].pixbuf;
+ return pb;
}
}
}
@@ -242,7 +245,7 @@ get_cover_art (const char *fname, const char *artist, const char *album, int wid
return NULL;
}
char *image_fname = coverart_plugin->get_album_art (fname, artist, album, cover_avail_callback, (void *)(intptr_t)width);
- if (fname) {
+ if (image_fname) {
GdkPixbuf *pb = get_pixbuf (image_fname, width);
free (image_fname);
return pb;