[libgsf] tar: fix reading of mode etc.



commit 237c07a8b7831978f525834fcb3fc1b99457e8dc
Author: Morten Welinder <terra gnome org>
Date:   Mon Apr 18 15:31:05 2016 -0400

    tar: fix reading of mode etc.
    
    It's unclear how octal fields are to be terminated.  Allow both space
    and NUL.

 ChangeLog            |    5 +++++
 NEWS                 |    3 +++
 gsf/gsf-infile-tar.c |   29 +++++++++++++++++++----------
 3 files changed, 27 insertions(+), 10 deletions(-)
---
diff --git a/ChangeLog b/ChangeLog
index 941686a..3c423a9 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,8 @@
+2016-04-18  Morten Welinder  <terra gnome org>
+
+       * gsf/gsf-infile-tar.c (unpack_octal): Allow a terminating space
+       instead of NUL.  Fixes #765099.
+
 2016-02-12  Morten Welinder <terra gnome org>
 
        * configure.ac: Post-release bump.
diff --git a/NEWS b/NEWS
index 3ea8e68..098e884 100644
--- a/NEWS
+++ b/NEWS
@@ -1,5 +1,8 @@
 libgsf 1.14.37
 
+Morten:
+       * Fix tar issue.   [#765099]
+
 --------------------------------------------------------------------------
 libgsf 1.14.36
 
diff --git a/gsf/gsf-infile-tar.c b/gsf/gsf-infile-tar.c
index 33068d2..271595d 100644
--- a/gsf/gsf-infile-tar.c
+++ b/gsf/gsf-infile-tar.c
@@ -98,21 +98,30 @@ typedef struct {
 static gint64
 unpack_octal (GsfInfileTar *tar, const char *s, size_t len)
 {
-       gint64 res = 0;
+       guint64 res = 0;
+
+       /*
+        * Different specifications differ on what terminating characters
+        * are allowed.  It doesn't hurt for us to allow both space and
+        * NUL.
+        */
+       if (len == 0 || (s[len - 1] != 0 && s[len - 1] != ' '))
+               goto invalid;
+       len--;
 
        while (len--) {
                unsigned char c = *s++;
-               if (c == 0)
-                       break;
-               if (c < '0' || c > '7') {
-                       tar->err = g_error_new (gsf_input_error_id (), 0,
-                                               _("Invalid tar header"));
-                       return 0;
-               }
-               res = (res << 3) + (c - '0');
+               if (c < '0' || c > '7')
+                       goto invalid;
+               res = (res << 3) | (c - '0');
        }
 
-       return res;
+       return (gint64)res;
+
+invalid:
+       tar->err = g_error_new (gsf_input_error_id (), 0,
+                               _("Invalid tar header"));
+       return 0;
 }
 
 


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]