diff mbox series

[v4,4/5] fs/squashfs: add support for LZO decompression

Message ID 20200818151725.11293-5-joaomarcos.costa@bootlin.com
State Accepted
Commit 6dfed163bd842bf98fd17875067bf8643819a879
Delegated to: Tom Rini
Headers show
Series fs/squashfs: Add new decompression algorithms | expand

Commit Message

Joao Marcos Costa Aug. 18, 2020, 3:17 p.m. UTC
Add call to lzo's lzo1x_decompress_safe() into sqfs_decompress().

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@bootlin.com>
---
Changes in v4:
	- No changes since the last version.
Changes in v3:
	- Change commit message.
Changes in v2:
	- Change commit message.
 fs/squashfs/sqfs_decompressor.c | 25 +++++++++++++++++++++++++
 1 file changed, 25 insertions(+)

Comments

Tom Rini Aug. 25, 2020, 12:16 p.m. UTC | #1
On Tue, Aug 18, 2020 at 05:17:24PM +0200, Joao Marcos Costa wrote:

> Add call to lzo's lzo1x_decompress_safe() into sqfs_decompress().
> 
> 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@bootlin.com>

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

Patch

diff --git a/fs/squashfs/sqfs_decompressor.c b/fs/squashfs/sqfs_decompressor.c
index 9457ee5f0f..d69ddb24a4 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
@@ -25,6 +30,10 @@  int sqfs_decompressor_init(struct squashfs_ctxt *ctxt)
 	u16 comp_type = get_unaligned_le16(&ctxt->sblk->compression);
 
 	switch (comp_type) {
+#if IS_ENABLED(CONFIG_LZO)
+	case SQFS_COMP_LZO:
+		break;
+#endif
 #if IS_ENABLED(CONFIG_ZLIB)
 	case SQFS_COMP_ZLIB:
 		break;
@@ -49,6 +58,10 @@  void sqfs_decompressor_cleanup(struct squashfs_ctxt *ctxt)
 	u16 comp_type = get_unaligned_le16(&ctxt->sblk->compression);
 
 	switch (comp_type) {
+#if IS_ENABLED(CONFIG_LZO)
+	case SQFS_COMP_LZO:
+		break;
+#endif
 #if IS_ENABLED(CONFIG_ZLIB)
 	case SQFS_COMP_ZLIB:
 		break;
@@ -101,6 +114,18 @@  int sqfs_decompress(struct squashfs_ctxt *ctxt, void *dest,
 	int ret = 0;
 
 	switch (comp_type) {
+#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
 #if IS_ENABLED(CONFIG_ZLIB)
 	case SQFS_COMP_ZLIB:
 		ret = uncompress(dest, dest_len, source, src_len);