Skip to content
Snippets Groups Projects
Commit 376ddf9d authored by Jean-Jacques Hiblot's avatar Jean-Jacques Hiblot Committed by Tom Rini
Browse files

gzip: add a function to parse the header

parent d753f942
No related branches found
No related tags found
No related merge requests found
......@@ -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);
......
......@@ -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
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment