summaryrefslogtreecommitdiff
blob: 63a4c13aefc1b7d916b2ae0c5a3482f72122ea5b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
--- libmms-0.2.orig/src/mms.c
+++ libmms-0.2/src/mms.c
@@ -144,7 +144,7 @@
   int           stream_types[ASF_MAX_NUM_STREAMS];
   off_t         start_packet_seq; /* for live streams != 0, need to keep it around */
   int           need_discont; /* whether we need to set start_packet_seq */
-  int           asf_packet_len;
+  uint32_t      asf_packet_len;
   uint64_t      file_len;
   char          guid[37];
   uint32_t      bitrates[ASF_MAX_NUM_STREAMS];
@@ -477,7 +477,7 @@
 }
 
 static void string_utf16(iconv_t url_conv, char *dest, char *src, int len) {
-    memset(dest, 0, 1000);
+    memset(dest, 0, 2 * len);
 
     if (url_conv == (iconv_t)-1) {
       int i;
@@ -503,7 +503,7 @@
 static void string_utf16(int unused, char *dest, char *src, int len) {
   int i;
 
-  memset (dest, 0, 1000);
+  memset (dest, 0, 2 * len);
 
   for (i = 0; i < len; i++) {
     dest[i * 2] = src[i];
@@ -539,13 +539,17 @@
       goto error;
     
     header->packet_len = LE_32(this->buf + 8) + 4;
+    if (header->packet_len > BUF_SIZE - 12) {
+        header->packet_len = 0;
+        goto error;
+    }
     lprintf("mms command\n");
     packet_type = MMS_PACKET_COMMAND;
   } else {
     header->packet_seq     = LE_32(this->buf);
     header->packet_id_type = this->buf[4];
     header->flags          = this->buf[5];
-    header->packet_len     = LE_16(this->buf + 6) - 8;
+    header->packet_len     = (LE_16(this->buf + 6) - 8) & 0xffff;
     if (header->packet_id_type == ASF_HEADER_PACKET_ID_TYPE) {
       lprintf("asf header\n");
       packet_type = MMS_PACKET_ASF_HEADER;
@@ -674,6 +678,11 @@
         break;
       case MMS_PACKET_ASF_HEADER:
       case MMS_PACKET_ASF_PACKET:
+        if (header.packet_len + this->asf_header_len > ASF_HEADER_LEN) {
+            lprintf( "***LOG:*** -- "
+                     "libmms: asf packet too large\n");
+            return 0;
+        }
         len = io_read(io,  this->s,
                               this->asf_header + this->asf_header_len, header.packet_len);
         if (len != header.packet_len) {
@@ -720,6 +729,12 @@
       case GUID_ASF_FILE_PROPERTIES:
 
         this->asf_packet_len = LE_32(this->asf_header + i + 92 - 24);
+        if (this->asf_packet_len > BUF_SIZE) {
+          this->asf_packet_len = 0;
+          lprintf( "***LOG:*** -- "
+                   "libmms: asf packet len too large\n");
+          break;
+        }
         this->file_len       = LE_64(this->asf_header + i + 40 - 24);
         lprintf ("file object, packet length = %d (%d)\n",
                  this->asf_packet_len, LE_32(this->asf_header + i + 96 - 24));
@@ -1420,8 +1435,20 @@
 
         /* explicit padding with 0 */
         lprintf("padding: %d bytes\n", this->asf_packet_len - header.packet_len);
-        memset(this->buf + header.packet_len, 0, this->asf_packet_len - header.packet_len);
-        this->buf_size = this->asf_packet_len;
+	{
+	  char *base  = (char *)(this->buf);
+	  char *start = base + header.packet_len;
+	  char *end   = start + this->asf_packet_len - header.packet_len;
+	  if ((start > base) && (start < (base+BUF_SIZE-1)) &&
+	      (start < end)  && (end < (base+BUF_SIZE-1))) {
+	    memset(this->buf + header.packet_len, 0, this->asf_packet_len - header.packet_len);
+ 	  }
+	  if (this->asf_packet_len > BUF_SIZE) {
+            this->buf_size = BUF_SIZE;
+          } else {
+            this->buf_size = this->asf_packet_len;
+          }
+	}
       }
       break;
   }
--- libmms-0.2.orig/src/mmsh.c
+++ libmms-0.2/src/mmsh.c
@@ -184,7 +184,7 @@
   int           num_stream_ids;
   int           stream_ids[ASF_MAX_NUM_STREAMS];
   int           stream_types[ASF_MAX_NUM_STREAMS];
-  int           packet_length;
+  uint32_t      packet_length;
   int64_t       file_length;
   char          guid[37];
   uint32_t      bitrates[ASF_MAX_NUM_STREAMS];
@@ -604,6 +604,10 @@
       case GUID_ASF_FILE_PROPERTIES:
 
         this->packet_length = LE_32(this->asf_header + i + 92 - 24);
+        if (this->packet_length > CHUNK_SIZE) {
+          this->packet_length = 0;
+          break;
+        }
         this->file_length   = LE_64(this->asf_header + i + 40 - 24);
         lprintf ("file object, packet length = %d (%d)\n",
 		 this->packet_length, LE_32(this->asf_header + i + 96 - 24));
@@ -1054,9 +1058,22 @@
 		 this->chunk_length, this->packet_length);
 	return 0;
       }
-      memset(this->buf + this->chunk_length, 0,
-             this->packet_length - this->chunk_length);
-      this->buf_size = this->packet_length;
+
+      {
+	char *base  = (char *)(this->buf);
+	char *start = base + this->chunk_length;
+	char *end   = start + this->packet_length - this->chunk_length;
+	if ((start > base) && (start < (base+CHUNK_SIZE-1)) &&
+	    (start < end)  && (end < (base+CHUNK_SIZE-1))) {
+	  memset(start, 0,
+		 this->packet_length - this->chunk_length);
+	}
+	if (this->packet_length > CHUNK_SIZE) {
+	  this->buf_size = CHUNK_SIZE;
+	} else {
+	  this->buf_size = this->packet_length;
+	}
+      }
       return 1;
     } else {
       lprintf ("mmsh: read error, %d != %d\n", len, this->chunk_length);