Signed-off-by: Jean-Jacques Hiblot <jjhib...@ti.com>
Reviewed-by: Tom Rini <tr...@konsulko.com>
Reviewed-by: Simon Glass <s...@chromium.org>
---
 no change since v3

 include/common.h |  1 +
 lib/gunzip.c     | 15 ++++++++++++---
 2 files changed, 13 insertions(+), 3 deletions(-)

diff --git a/include/common.h b/include/common.h
index c8fb277..8678275 100644
--- a/include/common.h
+++ b/include/common.h
@@ -568,6 +568,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);
diff --git a/lib/gunzip.c b/lib/gunzip.c
index 832b306..adb86c7 100644
--- a/lib/gunzip.c
+++ b/lib/gunzip.c
@@ -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
-- 
1.9.1

_______________________________________________
U-Boot mailing list
U-Boot@lists.denx.de
https://lists.denx.de/listinfo/u-boot

Reply via email to