diff options
author | Phillip Lougher <phillip@squashfs.org.uk> | 2013-06-21 03:59:25 +0100 |
---|---|---|
committer | Phillip Lougher <phillip@squashfs.org.uk> | 2013-06-21 03:59:25 +0100 |
commit | 78ce4e83e47e1f417878b3b78633cb619e9a0bae (patch) | |
tree | 426e9042c540777f472e07526ccb08d51021cf67 | |
parent | 34b15a717886eed0d3f530877c3056ae07dc0c6b (diff) | |
download | squashfs-tools-lz4.tar.gz |
unsquashfs: Call compressor_extract_optionslz4
Unsquashfs should have been calling compressor_extract_options to
check that it knew how to decompress a filesystem compressed with
the options stored in the filesystem.
As it happens xz compression up till now has been the only
compressor to use compression options, and the code has always
been able to decompress xz compressed filesystems whatever the
compression options used, and so the check hasn't been needed. But this
may change with other compressors.
Signed-off-by: Phillip Lougher <phillip@squashfs.org.uk>
-rw-r--r-- | squashfs-tools/unsquashfs.c | 45 |
1 files changed, 38 insertions, 7 deletions
diff --git a/squashfs-tools/unsquashfs.c b/squashfs-tools/unsquashfs.c index 5e8830f..b278aea 100644 --- a/squashfs-tools/unsquashfs.c +++ b/squashfs-tools/unsquashfs.c @@ -1731,6 +1731,42 @@ void squashfs_stat(char *source) } +int check_compression(struct compressor *comp) +{ + int res, bytes = 0; + char buffer[SQUASHFS_METADATA_SIZE] __attribute__ ((aligned)); + + if(!comp->supported) { + ERROR("Filesystem uses %s compression, this is " + "unsupported by this version\n", comp->name); + ERROR("Decompressors available:\n"); + display_compressors("", ""); + return 0; + } + + /* + * Read compression options from disk if present, and pass to + * the compressor to ensure we know how to decompress a filesystem + * compressed with these compression options. + * + * Note, even if there is no compression options we still call the + * compressor because some compression options may be mandatory + * for some compressors. + */ + if(SQUASHFS_COMP_OPTS(sBlk.s.flags)) { + bytes = read_block(fd, sizeof(sBlk.s), NULL, 0, buffer); + if(bytes == 0) { + ERROR("Failed to read compressor options\n"); + return 0; + } + } + + res = compressor_extract_options(comp, sBlk.s.block_size, buffer, bytes); + + return res != -1; +} + + int read_super(char *source) { squashfs_super_block_3 sBlk_3; @@ -2435,7 +2471,7 @@ int parse_number(char *arg, int *res) #define VERSION() \ - printf("unsquashfs version 4.2-git (2013/06/11)\n");\ + printf("unsquashfs version 4.2-git (2013/06/20)\n");\ printf("copyright (C) 2013 Phillip Lougher "\ "<phillip@squashfs.org.uk>\n\n");\ printf("This program is free software; you can redistribute it and/or"\ @@ -2650,13 +2686,8 @@ options: exit(0); } - if(!comp->supported) { - ERROR("Filesystem uses %s compression, this is " - "unsupported by this version\n", comp->name); - ERROR("Decompressors available:\n"); - display_compressors("", ""); + if(!check_compression(comp)) exit(1); - } block_size = sBlk.s.block_size; block_log = sBlk.s.block_log; |