changeset 451:5826c77f4acf trunk

[svn] - various overflow and security-related fixes from XMMS2 (mainly Juho Vaha-Herttua, et al)
author nenolod
date Wed, 17 Jan 2007 00:56:53 -0800
parents 357de698dab2
children 829f029fbd03
files ChangeLog src/aac/mp4ff/mp4ff.c src/aac/mp4ff/mp4ff.h src/aac/mp4ff/mp4ffint.h src/aac/mp4ff/mp4meta.c src/aac/mp4ff/mp4util.c
diffstat 6 files changed, 55 insertions(+), 18 deletions(-) [+]
line wrap: on
line diff
--- a/ChangeLog	Wed Jan 17 00:29:28 2007 -0800
+++ b/ChangeLog	Wed Jan 17 00:56:53 2007 -0800
@@ -1,3 +1,17 @@
+2007-01-17 08:29:28 +0000  William Pitcock <nenolod@sacredspiral.co.uk>
+  revision [984]
+  - remove broken iTunes 4/5 DRM support due to portability issues
+  
+  trunk/src/aac/mp4ff/Makefile     |    2 
+  trunk/src/aac/mp4ff/drms.c       | 1043 ---------------------------------------
+  trunk/src/aac/mp4ff/drms.h       |   40 -
+  trunk/src/aac/mp4ff/drmstables.h |  449 ----------------
+  trunk/src/aac/mp4ff/mp4atom.c    |  138 -----
+  trunk/src/aac/mp4ff/mp4ff.c      |   19 
+  trunk/src/aac/mp4ff/mp4ffint.h   |    1 
+  7 files changed, 1 insertion(+), 1691 deletions(-)
+
+
 2007-01-17 08:23:22 +0000  William Pitcock <nenolod@sacredspiral.co.uk>
   revision [982]
   - remove visual studio file from src/aac/mp4ff
--- a/src/aac/mp4ff/mp4ff.c	Wed Jan 17 00:29:28 2007 -0800
+++ b/src/aac/mp4ff/mp4ff.c	Wed Jan 17 00:56:53 2007 -0800
@@ -141,13 +141,6 @@
         f->file_size += size;
         f->last_atom = atom_type;
 
-        if (atom_type == ATOM_MDAT && f->moov_read)
-        {
-            /* moov atom is before mdat, we can stop reading when mdat is encountered */
-            /* file position will stay at beginning of mdat data */
-//            break;
-        }
-
         if (atom_type == ATOM_MOOV && size > header_size)
         {
             f->moov_read = 1;
--- a/src/aac/mp4ff/mp4ff.h	Wed Jan 17 00:29:28 2007 -0800
+++ b/src/aac/mp4ff/mp4ff.h	Wed Jan 17 00:56:53 2007 -0800
@@ -87,6 +87,7 @@
 int mp4ff_meta_get_num_items(const mp4ff_t *f);
 int mp4ff_meta_get_by_index(const mp4ff_t *f, unsigned int index,
                             char **item, char **value);
+int mp4ff_meta_find_by_name(const mp4ff_t *f, const char *item, char **value);
 int mp4ff_meta_get_title(const mp4ff_t *f, char **value);
 int mp4ff_meta_get_artist(const mp4ff_t *f, char **value);
 int mp4ff_meta_get_writer(const mp4ff_t *f, char **value);
@@ -107,6 +108,7 @@
 {
     char *item;
     char *value;
+    uint32_t value_length;
 } mp4ff_tag_t;
 
 /* metadata list structure */
--- a/src/aac/mp4ff/mp4ffint.h	Wed Jan 17 00:29:28 2007 -0800
+++ b/src/aac/mp4ff/mp4ffint.h	Wed Jan 17 00:56:53 2007 -0800
@@ -131,6 +131,7 @@
 {
     char *item;
     char *value;
+    uint32_t value_length;
 } mp4ff_tag_t;
 
 /* metadata list structure */
@@ -269,11 +270,11 @@
 
 #ifdef USE_TAGGING
 /* mp4meta.c */
+int32_t mp4ff_tag_add_field_len(mp4ff_metadata_t *tags, const char *item, const char *value, uint32_t valuelen);
 int32_t mp4ff_tag_add_field(mp4ff_metadata_t *tags, const char *item, const char *value);
 int32_t mp4ff_tag_set_field(mp4ff_metadata_t *tags, const char *item, const char *value);
 int32_t mp4ff_set_metadata_name(mp4ff_t *f, const uint8_t atom_type, unsigned char **name);
 int32_t mp4ff_parse_tag(mp4ff_t *f, const uint8_t parent_atom_type, const int32_t size);
-int32_t mp4ff_meta_find_by_name(const mp4ff_t *f, const char *item, char **value);
 int32_t mp4ff_parse_metadata(mp4ff_t *f, const int32_t size);
 int32_t mp4ff_tag_delete(mp4ff_metadata_t *tags);
 int32_t mp4ff_meta_get_num_items(const mp4ff_t *f);
--- a/src/aac/mp4ff/mp4meta.c	Wed Jan 17 00:29:28 2007 -0800
+++ b/src/aac/mp4ff/mp4meta.c	Wed Jan 17 00:56:53 2007 -0800
@@ -32,7 +32,7 @@
 #include <string.h>
 #include "mp4ffint.h"
 
-int32_t mp4ff_tag_add_field(mp4ff_metadata_t *tags, const char *item, const char *value)
+int32_t mp4ff_tag_add_field_len(mp4ff_metadata_t *tags, const char *item, const char *value, uint32_t valuelen)
 {
     void *backup = (void *)tags->tags;
 
@@ -45,7 +45,13 @@
         return 0;
     } else {
         tags->tags[tags->count].item = strdup(item);
-        tags->tags[tags->count].value = strdup(value);
+
+	/* ugly hack to make covers work */	
+        tags->tags[tags->count].value = malloc(valuelen+1);
+	memcpy(tags->tags[tags->count].value, value, valuelen);
+        tags->tags[tags->count].value[valuelen] = '\0';
+
+	tags->tags[tags->count].value_length = valuelen;
 
         if (!tags->tags[tags->count].item || !tags->tags[tags->count].value)
         {
@@ -53,6 +59,7 @@
             if (!tags->tags[tags->count].value) free (tags->tags[tags->count].value);
             tags->tags[tags->count].item = NULL;
             tags->tags[tags->count].value = NULL;
+            tags->tags[tags->count].value_length = 0;
             return 0;
         }
 
@@ -61,6 +68,11 @@
     }
 }
 
+int32_t mp4ff_tag_add_field(mp4ff_metadata_t *tags, const char *item, const char *value)
+{
+	return mp4ff_tag_add_field_len(tags, item, value, strlen(value));
+}
+
 int32_t mp4ff_tag_set_field(mp4ff_metadata_t *tags, const char *item, const char *value)
 {
     unsigned int i;
@@ -73,6 +85,7 @@
         {
 			free(tags->tags[i].value);
 			tags->tags[i].value = strdup(value);
+			tags->tags[i].value_length = strlen(value);
             return 1;
         }
     }
@@ -198,6 +211,7 @@
     uint64_t subsize, sumsize = 0;
     unsigned char * name = NULL;
     unsigned char * data = NULL;
+    uint32_t datalen = 0;
     uint32_t done = 0;
 
     while (sumsize < size)
@@ -259,6 +273,7 @@
 				{
 					if (data) {free(data);data = NULL;}
 					data = mp4ff_read_string(f,(uint32_t)(subsize-(header_size+8)));
+					datalen = (uint32_t)(subsize-(header_size+8));
 				}
 			} else if (atom_type == ATOM_NAME) {
 				if (!done)
@@ -279,7 +294,7 @@
 		if (!done)
 		{
 			if (name == NULL) mp4ff_set_metadata_name(f, parent_atom_type, &name);
-			if (name) mp4ff_tag_add_field(&(f->tags), (char*)name, (char*)data);
+			if (name) mp4ff_tag_add_field_len(&(f->tags), name, data, datalen);
 		}
 
 		free(data);
@@ -314,8 +329,13 @@
     {
         if (!stricmp(f->tags.tags[i].item, item))
         {
-			*value = strdup(f->tags.tags[i].value);
-            return 1;
+	    uint32_t value_length = f->tags.tags[i].value_length;
+	    
+	    if (value_length > 0) {
+		    *value = malloc(value_length+1);
+		    memcpy(*value, f->tags.tags[i].value, value_length+1);
+		    return value_length;
+	    }
         }
     }
 
--- a/src/aac/mp4ff/mp4util.c	Wed Jan 17 00:29:28 2007 -0800
+++ b/src/aac/mp4ff/mp4util.c	Wed Jan 17 00:56:53 2007 -0800
@@ -30,13 +30,20 @@
 
 int32_t mp4ff_read_data(mp4ff_t *f, uint8_t *data, uint32_t size)
 {
-    int32_t result = 1;
-
-    result = f->stream->read(f->stream->user_data, data, size);
+    int32_t result;
+    uint32_t read = 0;
 
-    f->current_position += size;
+    while (read < size) {
+        result = f->stream->read(f->stream->user_data, data+read, size-read);
+	if (result <= 0) {
+		break;
+	}
+	read += result;
+    }
 
-    return result;
+    f->current_position += read;
+
+    return read;
 }
 
 int32_t mp4ff_truncate(mp4ff_t * f)