Commit 1afc980c authored by conrad's avatar conrad

Merge branch '1.0-stable'

parents 293204b9 aee099bc
...@@ -147,11 +147,11 @@ The comment header is decoded as follows: ...@@ -147,11 +147,11 @@ The comment header is decoded as follows:
buf[base+2]=(char)((val)&0xff); buf[base+2]=(char)((val)&0xff);
static int static int
oggz_comment_validate_byname (const char * name, const char * value) oggz_comment_validate_byname (const char * name)
{ {
const char * c; const char * c;
if (!name || !value) return 0; if (!name) return 0;
for (c = name; *c; c++) { for (c = name; *c; c++) {
if (*c < 0x20 || *c > 0x7D || *c == 0x3D) { if (*c < 0x20 || *c > 0x7D || *c == 0x3D) {
...@@ -172,8 +172,8 @@ oggz_comment_new (const char * name, const char * value) ...@@ -172,8 +172,8 @@ oggz_comment_new (const char * name, const char * value)
{ {
OggzComment * comment; OggzComment * comment;
if (!oggz_comment_validate_byname (name, value)) return NULL; if (!oggz_comment_validate_byname (name)) return NULL;
/* Ensures that name != NULL, value != NULL, and validates strings */ /* Ensures that name != NULL and contains only valid characters */
comment = oggz_malloc (sizeof (OggzComment)); comment = oggz_malloc (sizeof (OggzComment));
if (comment == NULL) return NULL; if (comment == NULL) return NULL;
...@@ -184,11 +184,15 @@ oggz_comment_new (const char * name, const char * value) ...@@ -184,11 +184,15 @@ oggz_comment_new (const char * name, const char * value)
return NULL; return NULL;
} }
comment->value = oggz_strdup (value); if (value) {
if (comment->value == NULL) { comment->value = oggz_strdup (value);
oggz_free (comment->name); if (comment->value == NULL) {
oggz_free (comment); oggz_free (comment->name);
return NULL; oggz_free (comment);
return NULL;
}
} else {
comment->value = NULL;
} }
return comment; return comment;
...@@ -302,7 +306,7 @@ oggz_comment_first_byname (OGGZ * oggz, long serialno, char * name) ...@@ -302,7 +306,7 @@ oggz_comment_first_byname (OGGZ * oggz, long serialno, char * name)
if (name == NULL) return oggz_vector_nth_p (stream->comments, 0); if (name == NULL) return oggz_vector_nth_p (stream->comments, 0);
if (!oggz_comment_validate_byname (name, "")) if (!oggz_comment_validate_byname (name))
return NULL; return NULL;
for (i = 0; i < oggz_vector_size (stream->comments); i++) { for (i = 0; i < oggz_vector_size (stream->comments); i++) {
...@@ -397,7 +401,7 @@ oggz_comment_add (OGGZ * oggz, long serialno, const OggzComment * comment) ...@@ -397,7 +401,7 @@ oggz_comment_add (OGGZ * oggz, long serialno, const OggzComment * comment)
if (oggz->flags & OGGZ_WRITE) { if (oggz->flags & OGGZ_WRITE) {
if (OGGZ_CONFIG_WRITE) { if (OGGZ_CONFIG_WRITE) {
if (!oggz_comment_validate_byname (comment->name, comment->value)) if (!oggz_comment_validate_byname (comment->name))
return OGGZ_ERR_COMMENT_INVALID; return OGGZ_ERR_COMMENT_INVALID;
if (_oggz_comment_add_byname (stream, comment->name, comment->value) == NULL) if (_oggz_comment_add_byname (stream, comment->name, comment->value) == NULL)
...@@ -430,7 +434,7 @@ oggz_comment_add_byname (OGGZ * oggz, long serialno, ...@@ -430,7 +434,7 @@ oggz_comment_add_byname (OGGZ * oggz, long serialno,
if (oggz->flags & OGGZ_WRITE) { if (oggz->flags & OGGZ_WRITE) {
if (OGGZ_CONFIG_WRITE) { if (OGGZ_CONFIG_WRITE) {
if (!oggz_comment_validate_byname (name, value)) if (!oggz_comment_validate_byname (name))
return OGGZ_ERR_COMMENT_INVALID; return OGGZ_ERR_COMMENT_INVALID;
if (_oggz_comment_add_byname (stream, name, value) == NULL) if (_oggz_comment_add_byname (stream, name, value) == NULL)
...@@ -615,19 +619,22 @@ oggz_comments_decode (OGGZ * oggz, long serialno, ...@@ -615,19 +619,22 @@ oggz_comments_decode (OGGZ * oggz, long serialno,
c+=4; c+=4;
if (len>(size_t)(end-c)) return -1; if (len>(size_t)(end-c)) return -1;
n = 0;
name = c; name = c;
value = oggz_index_len (c, '=', len); value = oggz_index_len (c, '=', len);
if (value) { if (value) {
*value = '\0'; *value = '\0';
value++; value++;
n = c+len - value; n = c+len - value;
}
if (n != 0) {
if ((nvalue = oggz_strdup_len (value, n)) == NULL) if ((nvalue = oggz_strdup_len (value, n)) == NULL)
return OGGZ_ERR_OUT_OF_MEMORY; return OGGZ_ERR_OUT_OF_MEMORY;
#ifdef DEBUG #ifdef DEBUG
printf ("oggz_comments_decode: %s -> %s (length %d)\n", printf ("oggz_comments_decode: [%d] %s -> %s (length %d)\n",
name, nvalue, n); i, name, nvalue, n);
#endif #endif
if (_oggz_comment_add_byname (stream, name, nvalue) == NULL) { if (_oggz_comment_add_byname (stream, name, nvalue) == NULL) {
oggz_free (nvalue); oggz_free (nvalue);
...@@ -636,9 +643,19 @@ oggz_comments_decode (OGGZ * oggz, long serialno, ...@@ -636,9 +643,19 @@ oggz_comments_decode (OGGZ * oggz, long serialno,
oggz_free (nvalue); oggz_free (nvalue);
} else { } else {
/* For the case of a comment which is not in key=value form,
* duplicate exactly the length of the comment, as it is
* not NUL-terminated. In the case of the last comment of the
* packet, it will be followed immediately by a framing bit.
*/
if ((nvalue = oggz_strdup_len (name, len)) == NULL) if ((nvalue = oggz_strdup_len (name, len)) == NULL)
return OGGZ_ERR_OUT_OF_MEMORY; return OGGZ_ERR_OUT_OF_MEMORY;
#ifdef DEBUG
printf ("oggz_comments_decode: [%d] %s (no value) (length %d)\n",
i, nvalue, len);
#endif
if (_oggz_comment_add_byname (stream, nvalue, NULL) == NULL) { if (_oggz_comment_add_byname (stream, nvalue, NULL) == NULL) {
oggz_free (nvalue); oggz_free (nvalue);
return OGGZ_ERR_OUT_OF_MEMORY; return OGGZ_ERR_OUT_OF_MEMORY;
......
...@@ -73,18 +73,6 @@ main (int argc, char * argv[]) ...@@ -73,18 +73,6 @@ main (int argc, char * argv[])
FAIL ("Comment add to fresh bitstream failed"); FAIL ("Comment add to fresh bitstream failed");
if (err < 0) FAIL ("Operation failed"); if (err < 0) FAIL ("Operation failed");
INFO ("+ Testing add of invalid unstructured COMMENT byname");
err = oggz_comment_add_byname (oggz, serialno, COMMENT, NULL);
if (err != OGGZ_ERR_COMMENT_INVALID)
FAIL ("Invalid comment not detected");
INFO ("+ Testing add of invalid unstructured COMMENT from local storage");
mycomment.name = COMMENT;
mycomment.value = NULL;
err = oggz_comment_add (oggz, serialno, &mycomment);
if (err != OGGZ_ERR_COMMENT_INVALID)
FAIL ("Invalid comment not detected");
INFO ("+ Adding COPYRIGHT byname"); INFO ("+ Adding COPYRIGHT byname");
err = oggz_comment_add_byname (oggz, serialno, "COPYRIGHT", COPYRIGHT); err = oggz_comment_add_byname (oggz, serialno, "COPYRIGHT", COPYRIGHT);
if (err < 0) FAIL ("Operation failed"); if (err < 0) FAIL ("Operation failed");
...@@ -268,6 +256,15 @@ main (int argc, char * argv[]) ...@@ -268,6 +256,15 @@ main (int argc, char * argv[])
if(op) FAIL ("Returned comment packet for invalid serialno"); if(op) FAIL ("Returned comment packet for invalid serialno");
oggz_packet_destroy(op); oggz_packet_destroy(op);
INFO ("+ Testing add of valid plain (not key=value) COMMENT byname");
err = oggz_comment_add_byname (oggz, serialno, COMMENT, NULL);
if (err < 0) FAIL ("Operation failed");
INFO ("+ Testing add of valid plain (not key=value) COMMENT from local storage");
mycomment.name = COMMENT;
mycomment.value = NULL;
err = oggz_comment_add (oggz, serialno, &mycomment);
if (err < 0) FAIL ("Operation failed");
INFO ("+ Adding duplicate tag"); INFO ("+ Adding duplicate tag");
err = oggz_comment_add_byname (oggz, serialno, "PERFORMER", PERFORMER); err = oggz_comment_add_byname (oggz, serialno, "PERFORMER", PERFORMER);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment