diff mbox

[U-Boot,6/9] gzip: add a function to parse the header

Message ID 1500570157-24042-7-git-send-email-jjhiblot@ti.com
State Superseded
Delegated to: Tom Rini
Headers show

Commit Message

Jean-Jacques Hiblot July 20, 2017, 5:02 p.m. UTC
Signed-off-by: Jean-Jacques Hiblot <jjhiblot@ti.com>
---
 include/common.h |  1 +
 lib/gunzip.c     | 15 ++++++++++++---
 2 files changed, 13 insertions(+), 3 deletions(-)

Comments

Tom Rini July 24, 2017, 1:22 p.m. UTC | #1
On Thu, Jul 20, 2017 at 07:02:33PM +0200, Jean-Jacques Hiblot wrote:

> Signed-off-by: Jean-Jacques Hiblot <jjhiblot@ti.com>

Reviewed-by: Tom Rini <trini@konsulko.com>
Simon Glass Aug. 3, 2017, 3:25 p.m. UTC | #2
On 20 July 2017 at 11:02, Jean-Jacques Hiblot <jjhiblot@ti.com> wrote:
> Signed-off-by: Jean-Jacques Hiblot <jjhiblot@ti.com>
> ---
>  include/common.h |  1 +
>  lib/gunzip.c     | 15 ++++++++++++---
>  2 files changed, 13 insertions(+), 3 deletions(-)

Reviewed-by: Simon Glass <sjg@chromium.org>
diff mbox

Patch

diff --git a/include/common.h b/include/common.h
index 751665f..bff841f 100644
--- a/include/common.h
+++ b/include/common.h
@@ -567,6 +567,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