File size: 1,959 Bytes
4eaabb5
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
diff --git a/src/mapi_attr.c b/src/mapi_attr.c
index 3f3250b..455cc67 100644
--- a/src/mapi_attr.c
+++ b/src/mapi_attr.c
@@ -211,6 +211,8 @@ mapi_attr_read (size_t len, unsigned char *buf)
 		    CHECKINT32(idx, len); a->names[i].len = GETINT32(buf+idx); idx += 4;
 
 		    /* read the data into a buffer */
+                    /* read the data into a buffer */
+                    assert(a->names[i].len != 0);
                     assert(idx+a->names[i].len <= len);
 		    a->names[i].data = unicode_to_utf8(a->names[i].len, buf+idx);
 		    
diff --git a/src/util.c b/src/util.c
index 9a56e0e..db9e714 100644
--- a/src/util.c
+++ b/src/util.c
@@ -85,28 +85,29 @@ unicode_to_utf8 (size_t len, unsigned char* buf)
     int j = 0;
     unsigned char *utf8 = malloc (3 * len/2 + 1); /* won't get any longer than this */
 
-    for (i = 0; i < len - 1; i += 2)
-    {
-	uint32 c = GETINT16(buf + i);
-	if (c <= 0x007f)
-	{
-	    utf8[j++] = 0x00 | ((c & 0x007f) >> 0);
-	}
-	else if (c < 0x07ff)
-	{
-	    utf8[j++] = 0xc0 | ((c & 0x07c0) >> 6);
-	    utf8[j++] = 0x80 | ((c & 0x003f) >> 0);
-	}
-	else
-	{
-	    utf8[j++] = 0xe0 | ((c & 0xf000) >> 12);
-	    utf8[j++] = 0x80 | ((c & 0x0fc0) >> 6);
-	    utf8[j++] = 0x80 | ((c & 0x003f) >> 0);
-	}
+    if (len > 0) {
+        for (i = 0; i < len - 1; i += 2)
+        {
+            uint32 c = GETINT16(buf + i);
+            if (c <= 0x007f)
+            {
+                utf8[j++] = 0x00 | ((c & 0x007f) >> 0);
+            }
+            else if (c < 0x07ff)
+            {
+                utf8[j++] = 0xc0 | ((c & 0x07c0) >> 6);
+                utf8[j++] = 0x80 | ((c & 0x003f) >> 0);
+            }
+            else
+            {
+                utf8[j++] = 0xe0 | ((c & 0xf000) >> 12);
+                utf8[j++] = 0x80 | ((c & 0x0fc0) >> 6);
+                utf8[j++] = 0x80 | ((c & 0x003f) >> 0);
+            }
+        }
     }
-    
+
     utf8[j] = '\0';
-    
+
     return utf8;
 }
-