Made sure that all comments are well-formed before they are parsed.
authorTilman Sauerbeck <tilman@code-monkey.de>
Fri, 11 Aug 2006 13:34:19 +0000 (15:34 +0200)
committerTilman Sauerbeck <tilman@code-monkey.de>
Wed, 23 Aug 2006 17:33:24 +0000 (19:33 +0200)
ie, check that every comment has a '=' sign somewhere, but not at
position 0.

ext/ext.c

index d8bcc1271bed1232340be7eacd515216167176f1..4794d282dca70b4a66d20321a1eb24e9a7be2c45 100644 (file)
--- a/ext/ext.c
+++ b/ext/ext.c
@@ -130,7 +130,7 @@ c_init (VALUE self, VALUE io)
 {
        RbVorbisTagger *o;
        vorbis_comment *vc;
-       int s;
+       int s, i;
 
        Data_Get_Struct (self, RbVorbisTagger, o);
 
@@ -165,6 +165,15 @@ c_init (VALUE self, VALUE io)
                rb_raise (eVTError, "vcedit_comments() failed - %s",
                          vcedit_error (o->state));
 
+       /* check whether all comments are well-formed */
+       for (i = 0; i < vc->comments; i++) {
+               char *ptr, *content = vc->user_comments[i];
+
+               ptr = strchr (content, '=');
+               if (!ptr || ptr == content)
+                       rb_raise (eVTError, "malformed comment - %s", content);
+       }
+
        o->comments = rb_class_new_instance (0, NULL, cComments);
 
        comments_init (o->comments, o->state);