From e9cc570b83282a556f2e8897452e3ab152bc216e Mon Sep 17 00:00:00 2001 From: Magnus Holmgren Date: Mon, 1 May 2006 13:42:35 +0000 Subject: [PATCH] Applied patch 2917: Fix retrieval of total sample count in get_vorbis_metadata. git-svn-id: svn://svn.rockbox.org/rockbox/trunk@9850 a1c6a512-1295-4272-9138-f99709370657 --- apps/metadata.c | 25 ++++++++++++++++--------- 1 file changed, 16 insertions(+), 9 deletions(-) diff --git a/apps/metadata.c b/apps/metadata.c index 4b86bdff54..797192080f 100644 --- a/apps/metadata.c +++ b/apps/metadata.c @@ -556,7 +556,7 @@ static bool get_vorbis_metadata(int fd, struct mp3entry* id3) long comment_size; long remaining = 0; long last_serial = 0; - long serial; + long serial, r; int segments; int i; bool eof = false; @@ -652,7 +652,7 @@ static bool get_vorbis_metadata(int fd, struct mp3entry* id3) while (!eof) { - long r = read(fd, &buf[remaining], MAX_PATH - remaining); + r = read(fd, &buf[remaining], MAX_PATH - remaining); if (r <= 0) { @@ -666,7 +666,7 @@ static bool get_vorbis_metadata(int fd, struct mp3entry* id3) /* Inefficient (but simple) search */ i = 0; - while (i < (remaining - 5)) + while (i < (remaining - 3)) { if ((buf[i] == 'O') && (memcmp(&buf[i], "OggS", 4) == 0)) { @@ -677,8 +677,11 @@ static bool get_vorbis_metadata(int fd, struct mp3entry* id3) */ id3->samples = get_long(&buf[i + 6]); last_serial = get_long(&buf[i + 14]); - /* We can discard the rest of the buffer */ - remaining = 0; + + /* If this page is very small the beginning of the next + * header could be in buffer. Jump near end of this header + * and continue */ + i += 27; } else { @@ -691,16 +694,20 @@ static bool get_vorbis_metadata(int fd, struct mp3entry* id3) } } - if (i < (remaining - 5)) + if (i < remaining) { - /* Move OggS to start of buffer. */ - while (i >0) + /* Move the remaining bytes to start of buffer. + * Reuse var 'segments' as it is no longer needed */ + segments = 0; + while (i < remaining) { - buf[i--] = buf[remaining--]; + buf[segments++] = buf[i++]; } + remaining = segments; } else { + /* Discard the rest of the buffer */ remaining = 0; } }