]> git.ipfire.org Git - people/ms/u-boot.git/blobdiff - lib/gunzip.c
imx: hab: Check if CSF contains deprecated commands
[people/ms/u-boot.git] / lib / gunzip.c
index bc746d655e60aebc84c207c634728b3f1a4e1e40..adb86c755036fa9be8bf13b2717b5f6d21295868 100644 (file)
@@ -11,6 +11,7 @@
 #include <console.h>
 #include <image.h>
 #include <malloc.h>
+#include <memalign.h>
 #include <u-boot/zlib.h>
 #include <div64.h>
 
@@ -41,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;
 
@@ -62,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
@@ -193,7 +203,7 @@ int gzwrite(unsigned char *src, int len,
 
        s.next_in = src + i;
        s.avail_in = payload_size+8;
-       writebuf = (unsigned char *)malloc(szwritebuf);
+       writebuf = (unsigned char *)malloc_cache_aligned(szwritebuf);
 
        /* decompress until deflate stream ends or end of file */
        do {