]> git.ipfire.org Git - thirdparty/libarchive.git/commitdiff
Issue 394: Segfault when reading malformed old-style cpio archives
authorTim Kientzle <kientzle@acm.org>
Sat, 31 Jan 2015 07:54:19 +0000 (23:54 -0800)
committerTim Kientzle <kientzle@acm.org>
Sat, 31 Jan 2015 07:54:19 +0000 (23:54 -0800)
Root cause here was an implicit cast that resulted in
reading very large file sizes as negative numbers.

libarchive/archive_read_support_format_cpio.c

index 0b6968980bedb1243811fb6fe4de56188c80c94b..e7b3d0c1d8a12c3da16094feca82d990d451b3e7 100644 (file)
@@ -198,7 +198,7 @@ static int  archive_read_format_cpio_read_data(struct archive_read *,
 static int     archive_read_format_cpio_read_header(struct archive_read *,
                    struct archive_entry *);
 static int     archive_read_format_cpio_skip(struct archive_read *);
-static int     be4(const unsigned char *);
+static int64_t be4(const unsigned char *);
 static int     find_odc_header(struct archive_read *);
 static int     find_newc_header(struct archive_read *);
 static int     header_bin_be(struct archive_read *, struct cpio *,
@@ -213,7 +213,7 @@ static int  header_afiol(struct archive_read *, struct cpio *,
                    struct archive_entry *, size_t *, size_t *);
 static int     is_octal(const char *, size_t);
 static int     is_hex(const char *, size_t);
-static int     le4(const unsigned char *);
+static int64_t le4(const unsigned char *);
 static int     record_hardlink(struct archive_read *a,
                    struct cpio *cpio, struct archive_entry *entry);
 
@@ -946,17 +946,17 @@ archive_read_format_cpio_cleanup(struct archive_read *a)
        return (ARCHIVE_OK);
 }
 
-static int
+static int64_t
 le4(const unsigned char *p)
 {
-       return ((p[0]<<16) + (p[1]<<24) + (p[2]<<0) + (p[3]<<8));
+       return ((p[0] << 16) + (((int64_t)p[1]) << 24) + (p[2] << 0) + (p[3] << 8));
 }
 
 
-static int
+static int64_t
 be4(const unsigned char *p)
 {
-       return ((p[0]<<24) + (p[1]<<16) + (p[2]<<8) + (p[3]));
+       return ((((int64_t)p[0]) << 24) + (p[1] << 16) + (p[2] << 8) + (p[3]));
 }
 
 /*