Commit 376ddf9d4a21d0af4c70e97c52e5f0854fb2d696

Authored by Jean-Jacques Hiblot
Committed by Tom Rini
1 parent d753f942ec

gzip: add a function to parse the header

Signed-off-by: Jean-Jacques Hiblot <jjhiblot@ti.com>
Reviewed-by: Tom Rini <trini@konsulko.com>
Reviewed-by: Simon Glass <sjg@chromium.org>

Showing 2 changed files with 13 additions and 3 deletions Side-by-side Diff

... ... @@ -609,6 +609,7 @@
609 609 ulong ticks2usec (unsigned long ticks);
610 610  
611 611 /* lib/gunzip.c */
  612 +int gzip_parse_header(const unsigned char *src, unsigned long len);
612 613 int gunzip(void *, int, unsigned char *, unsigned long *);
613 614 int zunzip(void *dst, int dstlen, unsigned char *src, unsigned long *lenp,
614 615 int stoponerr, int offset);
... ... @@ -42,7 +42,7 @@
42 42 free (addr);
43 43 }
44 44  
45   -int gunzip(void *dst, int dstlen, unsigned char *src, unsigned long *lenp)
  45 +int gzip_parse_header(const unsigned char *src, unsigned long len)
46 46 {
47 47 int i, flags;
48 48  
49 49  
50 50  
... ... @@ -63,12 +63,21 @@
63 63 ;
64 64 if ((flags & HEAD_CRC) != 0)
65 65 i += 2;
66   - if (i >= *lenp) {
  66 + if (i >= len) {
67 67 puts ("Error: gunzip out of data in header\n");
68 68 return (-1);
69 69 }
  70 + return i;
  71 +}
70 72  
71   - return zunzip(dst, dstlen, src, lenp, 1, i);
  73 +int gunzip(void *dst, int dstlen, unsigned char *src, unsigned long *lenp)
  74 +{
  75 + int offset = gzip_parse_header(src, *lenp);
  76 +
  77 + if (offset < 0)
  78 + return offset;
  79 +
  80 + return zunzip(dst, dstlen, src, lenp, 1, offset);
72 81 }
73 82  
74 83 #ifdef CONFIG_CMD_UNZIP