aboutsummaryrefslogtreecommitdiff
path: root/libid3tag
diff options
context:
space:
mode:
authorSergey Poznyakoff <gray@gnu.org.ua>2011-03-26 23:01:50 +0200
committerSergey Poznyakoff <gray@gnu.org.ua>2011-03-26 23:01:50 +0200
commit65bfbf2c783c82f22074fb2653105692ec354c3c (patch)
treefe2bbae705c88d56aba6a714edb3fbc21c8f364a /libid3tag
parentf4692d0867aac664180cd20e0eb7c52f6a931f76 (diff)
downloadidest-65bfbf2c783c82f22074fb2653105692ec354c3c.tar.gz
idest-65bfbf2c783c82f22074fb2653105692ec354c3c.tar.bz2
libid3tag: Fix writing v2 tags to a clean mp3 file.
This fixes a bug introduced by 4c887e9caf. * libid3tag/file.c (v2_write): Proceed even if ntags is 0, but take care not to dereference file->tags. After writing, add new tag to the file.
Diffstat (limited to 'libid3tag')
-rw-r--r--libid3tag/file.c24
1 files changed, 13 insertions, 11 deletions
diff --git a/libid3tag/file.c b/libid3tag/file.c
index 8c1aa54..1feb504 100644
--- a/libid3tag/file.c
+++ b/libid3tag/file.c
@@ -727,8 +727,6 @@ v2_write(struct id3_file *file,
727{ 727{
728 int rc; 728 int rc;
729 729
730 if (file->ntags == 0)
731 return 0;
732 if (data && 730 if (data &&
733 ((file->ntags == 1 && !(file->flags & ID3_FILE_FLAG_ID3V1)) || 731 ((file->ntags == 1 && !(file->flags & ID3_FILE_FLAG_ID3V1)) ||
734 (file->ntags == 2 && (file->flags & ID3_FILE_FLAG_ID3V1))) && 732 (file->ntags == 2 && (file->flags & ID3_FILE_FLAG_ID3V1))) &&
@@ -769,14 +767,17 @@ v2_write(struct id3_file *file,
769 * FIXME: Should I check 767 * FIXME: Should I check
770 * tag->version instead? 768 * tag->version instead?
771 */ 769 */
772 (file->tags[0].location == 0) ? 770 (file->ntags > 0 &&
771 file->tags[0].location == 0) ?
773 file->tags[0].length : 0, -1); 772 file->tags[0].length : 0, -1);
774 773
775 fclose(tmp); 774 fclose(tmp);
776 if (rc) 775 if (rc)
777 unlink(tmpname); 776 unlink(tmpname);
778 else { 777 else {
779 file->tags[0].length = length; 778 if (file->ntags > 0)
779 file->tags[0].length = length;
780
780 fclose(file->iofile); 781 fclose(file->iofile);
781 rc = unlink(file->path); 782 rc = unlink(file->path);
782 if (rc == 0) { 783 if (rc == 0) {
@@ -784,6 +785,11 @@ v2_write(struct id3_file *file,
784 chmod(file->path, st.st_mode & 0777); 785 chmod(file->path, st.st_mode & 0777);
785 chown(file->path, st.st_uid, st.st_gid); 786 chown(file->path, st.st_uid, st.st_gid);
786 file->iofile = fopen(file->path, "r+b"); 787 file->iofile = fopen(file->path, "r+b");
788 if (file->ntags == 0)
789 add_tag(file, length);
790 /* FIXME: See also comment after the
791 call to this function in id3_file_update.
792 */
787 } 793 }
788 } 794 }
789 free(tmpname); 795 free(tmpname);
@@ -798,13 +804,9 @@ v2_write(struct id3_file *file,
798int 804int
799id3_file_update(struct id3_file *file) 805id3_file_update(struct id3_file *file)
800{ 806{
801 int options, 807 int options, result = 0;
802 result = 0; 808 id3_length_t v1size = 0, v2size = 0;
803 id3_length_t v1size = 0, 809 id3_byte_t id3v1_data[128], *id3v1 = 0, *id3v2 = 0;
804 v2size = 0;
805 id3_byte_t id3v1_data[128],
806 *id3v1 = 0,
807 *id3v2 = 0;
808 810
809 assert(file); 811 assert(file);
810 812

Return to:

Send suggestions and report system problems to the System administrator.