Made sure that all comments are well-formed before they are parsed.
[ruby-vorbistagger.git] / 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);