]> git.ipfire.org Git - people/ms/u-boot.git/commitdiff
gzip: add a function to parse the header
authorJean-Jacques Hiblot <jjhiblot@ti.com>
Fri, 15 Sep 2017 10:57:29 +0000 (12:57 +0200)
committerTom Rini <trini@konsulko.com>
Fri, 6 Oct 2017 01:31:04 +0000 (21:31 -0400)
Signed-off-by: Jean-Jacques Hiblot <jjhiblot@ti.com>
Reviewed-by: Tom Rini <trini@konsulko.com>
Reviewed-by: Simon Glass <sjg@chromium.org>
include/common.h
lib/gunzip.c

index 18963355840d9890d7721807468cbce19ab872fc..4b521e142a9e7d53c2093e4e160d5962a122bffe 100644 (file)
@@ -609,6 +609,7 @@ ulong       usec2ticks    (unsigned long usec);
 ulong  ticks2usec    (unsigned long ticks);
 
 /* lib/gunzip.c */
+int gzip_parse_header(const unsigned char *src, unsigned long len);
 int gunzip(void *, int, unsigned char *, unsigned long *);
 int zunzip(void *dst, int dstlen, unsigned char *src, unsigned long *lenp,
                                                int stoponerr, int offset);
index 832b3064e7614bc7c74159ca04f62b3122420356..adb86c755036fa9be8bf13b2717b5f6d21295868 100644 (file)
@@ -42,7 +42,7 @@ void gzfree(void *x, void *addr, unsigned nb)
        free (addr);
 }
 
-int gunzip(void *dst, int dstlen, unsigned char *src, unsigned long *lenp)
+int gzip_parse_header(const unsigned char *src, unsigned long len)
 {
        int i, flags;
 
@@ -63,12 +63,21 @@ int gunzip(void *dst, int dstlen, unsigned char *src, unsigned long *lenp)
                        ;
        if ((flags & HEAD_CRC) != 0)
                i += 2;
-       if (i >= *lenp) {
+       if (i >= len) {
                puts ("Error: gunzip out of data in header\n");
                return (-1);
        }
+       return i;
+}
+
+int gunzip(void *dst, int dstlen, unsigned char *src, unsigned long *lenp)
+{
+       int offset = gzip_parse_header(src, *lenp);
+
+       if (offset < 0)
+               return offset;
 
-       return zunzip(dst, dstlen, src, lenp, 1, i);
+       return zunzip(dst, dstlen, src, lenp, 1, offset);
 }
 
 #ifdef CONFIG_CMD_UNZIP