summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--unpack/rdsquashfs.c40
1 files changed, 24 insertions, 16 deletions
diff --git a/unpack/rdsquashfs.c b/unpack/rdsquashfs.c
index deba5be..3c80853 100644
--- a/unpack/rdsquashfs.c
+++ b/unpack/rdsquashfs.c
@@ -110,6 +110,26 @@ static char *get_path(char *old, const char *arg)
return path;
}
+static int load_fragment_table(unsqfs_info_t *info, sqfs_super_t *super)
+{
+ if (super->fragment_entry_count == 0)
+ return 0;
+
+ if (super->flags & SQFS_FLAG_NO_FRAGMENTS)
+ return 0;
+
+ if (super->fragment_table_start >= super->bytes_used) {
+ fputs("Fragment table start is past end of file\n", stderr);
+ return -1;
+ }
+
+ info->frag = frag_reader_create(super, info->sqfsfd, info->cmp);
+ if (info->frag == NULL)
+ return -1;
+
+ return 0;
+}
+
int main(int argc, char **argv)
{
int i, status = EXIT_FAILURE, op = OP_NONE;
@@ -251,14 +271,8 @@ int main(int argc, char **argv)
goto out_fs;
}
- if (super.fragment_entry_count > 0 &&
- super.fragment_table_start < super.bytes_used &&
- !(super.flags & SQFS_FLAG_NO_FRAGMENTS)) {
- info.frag = frag_reader_create(&super, info.sqfsfd,
- info.cmp);
- if (info.frag == NULL)
- goto out_fs;
- }
+ if (load_fragment_table(&info, &super))
+ goto out_fs;
if (extract_file(n->data.file, &info, STDOUT_FILENO))
goto out_fs;
@@ -274,14 +288,8 @@ int main(int argc, char **argv)
}
}
- if (super.fragment_entry_count > 0 &&
- super.fragment_table_start < super.bytes_used &&
- !(super.flags & SQFS_FLAG_NO_FRAGMENTS)) {
- info.frag = frag_reader_create(&super, info.sqfsfd,
- info.cmp);
- if (info.frag == NULL)
- goto out_fs;
- }
+ if (load_fragment_table(&info, &super))
+ goto out_fs;
if (restore_fstree(unpack_root, n, &info))
goto out_fs;