[PATCH v2 1/4] fs/squashfs: add support for LZO decompression

Joao Marcos Costa joaomarcos.costa at bootlin.com
Tue Aug 18 15:08:38 CEST 2020


Add call to lzo's lzo1x_decompress_safe() and rename source length
parameter from 'lenp' to 'src_len'.

U-Boot's LZO sources may still have some unsolved issues that could make the
decompression crash when dealing with fragmented files, so those should be
avoided. The "-no-fragments" option can be passed to mksquashfs.

Signed-off-by: Joao Marcos Costa <joaomarcos.costa at bootlin.com>
---
Changes in v2:
	- Changed commit message.
 fs/squashfs/sqfs_decompressor.c | 21 +++++++++++++++++++--
 1 file changed, 19 insertions(+), 2 deletions(-)

diff --git a/fs/squashfs/sqfs_decompressor.c b/fs/squashfs/sqfs_decompressor.c
index 09ca6cf6d0..9285df5d3b 100644
--- a/fs/squashfs/sqfs_decompressor.c
+++ b/fs/squashfs/sqfs_decompressor.c
@@ -9,6 +9,11 @@
 #include <stdint.h>
 #include <stdio.h>
 #include <stdlib.h>
+
+#if IS_ENABLED(CONFIG_LZO)
+#include <linux/lzo.h>
+#endif
+
 #if IS_ENABLED(CONFIG_ZLIB)
 #include <u-boot/zlib.h>
 #endif
@@ -35,20 +40,32 @@ static void zlib_decompression_status(int ret)
 #endif
 
 int sqfs_decompress(u16 comp_type, void *dest, unsigned long *dest_len,
-		    void *source, u32 lenp)
+		    void *source, u32 src_len)
 {
 	int ret = 0;
 
 	switch (comp_type) {
 #if IS_ENABLED(CONFIG_ZLIB)
 	case SQFS_COMP_ZLIB:
-		ret = uncompress(dest, dest_len, source, lenp);
+		ret = uncompress(dest, dest_len, source, src_len);
 		if (ret) {
 			zlib_decompression_status(ret);
 			return -EINVAL;
 		}
 
 		break;
+#endif
+#if IS_ENABLED(CONFIG_LZO)
+	case SQFS_COMP_LZO: {
+		size_t lzo_dest_len = *dest_len;
+		ret = lzo1x_decompress_safe(source, src_len, dest, &lzo_dest_len);
+		if (ret) {
+			printf("LZO decompression failed. Error code: %d\n", ret);
+			return -EINVAL;
+		}
+
+		break;
+	}
 #endif
 	default:
 		printf("Error: unknown compression type.\n");
-- 
2.17.1



More information about the U-Boot mailing list