]> git.ipfire.org Git - thirdparty/libarchive.git/commitdiff
Additional fix to issue 247(Unicode filenames in RAR).
authorMichihiro NAKAJIMA <ggcueroad@gmail.com>
Wed, 7 Mar 2012 04:00:24 +0000 (13:00 +0900)
committerMichihiro NAKAJIMA <ggcueroad@gmail.com>
Wed, 7 Mar 2012 04:00:24 +0000 (13:00 +0900)
libarchive/archive_read_support_format_rar.c

index d31708500202ac1f374922b763a33c3d0323bc1e..5eda9cb30d3af819c6f1ebe0644eb90e5c5bd671 100644 (file)
@@ -1161,8 +1161,8 @@ read_header(struct archive_read *a, struct archive_entry *entry,
       "Invalid filename size");
     return (ARCHIVE_FATAL);
   }
-  if (rar->filename_allocated < filename_size+2) {
-    rar->filename = realloc(rar->filename, filename_size+2);
+  if (rar->filename_allocated < filename_size * 2 + 2) {
+    rar->filename = realloc(rar->filename, filename_size * 2 + 2);
     if (rar->filename == NULL) {
       archive_set_error(&a->archive, ENOMEM,
                         "Couldn't allocate memory.");
@@ -1177,14 +1177,16 @@ read_header(struct archive_read *a, struct archive_entry *entry,
     if (filename_size != strlen(filename))
     {
       unsigned char highbyte, flagbits, flagbyte, offset;
+      unsigned fn_end;
 
       end = filename_size;
+      fn_end = filename_size * 2;
       filename_size = 0;
       offset = strlen(filename) + 1;
       highbyte = *(p + offset++);
       flagbits = 0;
       flagbyte = 0;
-      while (offset < end && filename_size < end)
+      while (offset < end && filename_size < fn_end)
       {
         if (!flagbits)
         {
@@ -1219,7 +1221,7 @@ read_header(struct archive_read *a, struct archive_entry *entry,
             } else
               extra = high = 0;
             length = (length & 0x7f) + 2;
-            while (length && filename_size < end) {
+            while (length && filename_size < fn_end) {
               unsigned cp = filename_size >> 1;
               filename[filename_size++] = high;
               filename[filename_size++] = p[cp] + extra;
@@ -1229,7 +1231,7 @@ read_header(struct archive_read *a, struct archive_entry *entry,
           break;
         }
       }
-      if (filename_size >end) {
+      if (filename_size > fn_end) {
         archive_set_error(&a->archive, ARCHIVE_ERRNO_FILE_FORMAT,
           "Invalid filename");
         return (ARCHIVE_FATAL);