From c96280bd3de4c54f1c1762ab6e0321425d126a26 Mon Sep 17 00:00:00 2001 From: waker Date: Mon, 4 Apr 2011 21:29:38 +0200 Subject: m3u: removed file size limitation on playlist files --- plugins/m3u/m3u.c | 34 ++++++++++++++++------------------ 1 file changed, 16 insertions(+), 18 deletions(-) (limited to 'plugins/m3u') diff --git a/plugins/m3u/m3u.c b/plugins/m3u/m3u.c index 27193bf4..3f22be94 100644 --- a/plugins/m3u/m3u.c +++ b/plugins/m3u/m3u.c @@ -49,18 +49,13 @@ load_m3u (DB_playItem_t *after, const char *fname, int *pabort, int (*cb)(DB_pla return NULL; } int sz = deadbeef->fgetlength (fp); - if (sz > 1024*1024) { - deadbeef->fclose (fp); - trace ("file %s is too large to be a playlist\n", fname); - return NULL; - } - if (sz < 30) { + trace ("loading m3u...\n"); + uint8_t *buffer = malloc (sz); + if (!buffer) { deadbeef->fclose (fp); - trace ("file %s is too small to be a playlist (%d)\n", fname, sz); + trace ("failed to allocate %d bytes to read the file %s\n", sz, fname); return NULL; } - trace ("loading m3u...\n"); - uint8_t buffer[sz]; deadbeef->fread (buffer, 1, sz, fp); deadbeef->fclose (fp); const uint8_t *p = buffer; @@ -107,6 +102,7 @@ load_m3u (DB_playItem_t *after, const char *fname, int *pabort, int (*cb)(DB_pla } if (pabort && *pabort) { deadbeef->pl_unlock (); + free (buffer); return after; } p = e; @@ -116,6 +112,7 @@ load_m3u (DB_playItem_t *after, const char *fname, int *pabort, int (*cb)(DB_pla } deadbeef->pl_unlock (); trace ("leave pl_insert_m3u\n"); + free (buffer); return after; } @@ -154,18 +151,13 @@ load_pls (DB_playItem_t *after, const char *fname, int *pabort, int (*cb)(DB_pla return NULL; } int sz = deadbeef->fgetlength (fp); - if (sz > 1024*1024) { - deadbeef->fclose (fp); - trace ("file %s is too large to be a playlist\n", fname); - return NULL; - } - if (sz < 30) { + deadbeef->rewind (fp); + uint8_t *buffer = malloc (sz); + if (!buffer) { deadbeef->fclose (fp); - trace ("file %s is too small to be a playlist (%d)\n", fname, sz); + trace ("failed to allocate %d bytes to read the file %s\n", sz, fname); return NULL; } - deadbeef->rewind (fp); - uint8_t buffer[sz]; deadbeef->fread (buffer, 1, sz, fp); deadbeef->fclose (fp); // 1st line must be "[playlist]" @@ -173,12 +165,14 @@ load_pls (DB_playItem_t *after, const char *fname, int *pabort, int (*cb)(DB_pla const uint8_t *end = buffer+sz; if (strncasecmp (p, "[playlist]", 10)) { trace ("file %s doesn't begin with [playlist]\n", fname); + free (buffer); return NULL; } p += 10; p = skipspaces (p, end); if (p >= end) { trace ("file %s finished before numberofentries had been read\n", fname); + free (buffer); return NULL; } // fetch all tracks @@ -213,6 +207,7 @@ load_pls (DB_playItem_t *after, const char *fname, int *pabort, int (*cb)(DB_pla } if (pabort && *pabort) { deadbeef->pl_unlock (); + free (buffer); return after; } uri[0] = 0; @@ -250,6 +245,7 @@ load_pls (DB_playItem_t *after, const char *fname, int *pabort, int (*cb)(DB_pla } if (pabort && *pabort) { deadbeef->pl_unlock (); + free (buffer); return after; } uri[0] = 0; @@ -286,6 +282,7 @@ load_pls (DB_playItem_t *after, const char *fname, int *pabort, int (*cb)(DB_pla } if (pabort && *pabort) { deadbeef->pl_unlock (); + free (buffer); return after; } uri[0] = 0; @@ -327,6 +324,7 @@ load_pls (DB_playItem_t *after, const char *fname, int *pabort, int (*cb)(DB_pla } } deadbeef->pl_unlock (); + free (buffer); return after; } -- cgit v1.2.3