summaryrefslogtreecommitdiff
path: root/apps
diff options
context:
space:
mode:
Diffstat (limited to 'apps')
-rw-r--r--apps/metadata.c25
1 files 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)
556 long comment_size; 556 long comment_size;
557 long remaining = 0; 557 long remaining = 0;
558 long last_serial = 0; 558 long last_serial = 0;
559 long serial; 559 long serial, r;
560 int segments; 560 int segments;
561 int i; 561 int i;
562 bool eof = false; 562 bool eof = false;
@@ -652,7 +652,7 @@ static bool get_vorbis_metadata(int fd, struct mp3entry* id3)
652 652
653 while (!eof) 653 while (!eof)
654 { 654 {
655 long r = read(fd, &buf[remaining], MAX_PATH - remaining); 655 r = read(fd, &buf[remaining], MAX_PATH - remaining);
656 656
657 if (r <= 0) 657 if (r <= 0)
658 { 658 {
@@ -666,7 +666,7 @@ static bool get_vorbis_metadata(int fd, struct mp3entry* id3)
666 /* Inefficient (but simple) search */ 666 /* Inefficient (but simple) search */
667 i = 0; 667 i = 0;
668 668
669 while (i < (remaining - 5)) 669 while (i < (remaining - 3))
670 { 670 {
671 if ((buf[i] == 'O') && (memcmp(&buf[i], "OggS", 4) == 0)) 671 if ((buf[i] == 'O') && (memcmp(&buf[i], "OggS", 4) == 0))
672 { 672 {
@@ -677,8 +677,11 @@ static bool get_vorbis_metadata(int fd, struct mp3entry* id3)
677 */ 677 */
678 id3->samples = get_long(&buf[i + 6]); 678 id3->samples = get_long(&buf[i + 6]);
679 last_serial = get_long(&buf[i + 14]); 679 last_serial = get_long(&buf[i + 14]);
680 /* We can discard the rest of the buffer */ 680
681 remaining = 0; 681 /* If this page is very small the beginning of the next
682 * header could be in buffer. Jump near end of this header
683 * and continue */
684 i += 27;
682 } 685 }
683 else 686 else
684 { 687 {
@@ -691,16 +694,20 @@ static bool get_vorbis_metadata(int fd, struct mp3entry* id3)
691 } 694 }
692 } 695 }
693 696
694 if (i < (remaining - 5)) 697 if (i < remaining)
695 { 698 {
696 /* Move OggS to start of buffer. */ 699 /* Move the remaining bytes to start of buffer.
697 while (i >0) 700 * Reuse var 'segments' as it is no longer needed */
701 segments = 0;
702 while (i < remaining)
698 { 703 {
699 buf[i--] = buf[remaining--]; 704 buf[segments++] = buf[i++];
700 } 705 }
706 remaining = segments;
701 } 707 }
702 else 708 else
703 { 709 {
710 /* Discard the rest of the buffer */
704 remaining = 0; 711 remaining = 0;
705 } 712 }
706 } 713 }