diff mbox

[U-Boot] lib/lzo: bugfix when input data is not compressed

Message ID 1466153218-973-1-git-send-email-joris.lijssens@gmail.com
State Accepted
Commit a2cfc8d5935efd445d9f9b258383e2a42f83ef6e
Delegated to: Tom Rini
Headers show

Commit Message

Joris Lijssens June 17, 2016, 8:46 a.m. UTC
When the input data is not compressed at all,
lzo1x_decompress_safe will fail, so call memcpy()
instead.

Signed-off-by: Joris Lijssens <joris.lijssens@gmail.com>
---

 lib/lzo/lzo1x_decompress.c | 25 ++++++++++++++++---------
 1 file changed, 16 insertions(+), 9 deletions(-)

Comments

Tom Rini June 25, 2016, 2:52 a.m. UTC | #1
On Fri, Jun 17, 2016 at 10:46:58AM +0200, Joris Lijssens wrote:

> When the input data is not compressed at all,
> lzo1x_decompress_safe will fail, so call memcpy()
> instead.
> 
> Signed-off-by: Joris Lijssens <joris.lijssens@gmail.com>

Applied to u-boot/master, thanks!
diff mbox

Patch

diff --git a/lib/lzo/lzo1x_decompress.c b/lib/lzo/lzo1x_decompress.c
index ebdf10b..ccc90b8 100644
--- a/lib/lzo/lzo1x_decompress.c
+++ b/lib/lzo/lzo1x_decompress.c
@@ -98,18 +98,25 @@  int lzop_decompress(const unsigned char *src, size_t src_len,
 		if (dlen > remaining)
 			return LZO_E_OUTPUT_OVERRUN;
 
-		/* decompress */
-		tmp = dlen;
-		r = lzo1x_decompress_safe((u8 *) src, slen, dst, &tmp);
+		/* When the input data is not compressed at all,
+		 * lzo1x_decompress_safe will fail, so call memcpy()
+		 * instead */
+		if (dlen == slen) {
+			memcpy(dst, src, slen);
+		} else {
+			/* decompress */
+			tmp = dlen;
+			r = lzo1x_decompress_safe((u8 *)src, slen, dst, &tmp);
+
+			if (r != LZO_E_OK) {
+				*dst_len = dst - start;
+				return r;
+			}
 
-		if (r != LZO_E_OK) {
-			*dst_len = dst - start;
-			return r;
+			if (dlen != tmp)
+				return LZO_E_ERROR;
 		}
 
-		if (dlen != tmp)
-			return LZO_E_ERROR;
-
 		src += slen;
 		dst += dlen;
 		remaining -= dlen;