63535b
diff --git a/squashfs-tools/unsquash-4.c b/squashfs-tools/unsquash-4.c
63535b
index ecdaac796f09..2c0cf63daf67 100644
63535b
--- a/squashfs-tools/unsquash-4.c
63535b
+++ b/squashfs-tools/unsquash-4.c
63535b
@@ -31,9 +31,9 @@ static unsigned int *id_table;
63535b
 int read_fragment_table_4(long long *directory_table_end)
63535b
 {
63535b
 	int res, i;
63535b
-	int bytes = SQUASHFS_FRAGMENT_BYTES(sBlk.s.fragments);
63535b
-	int  indexes = SQUASHFS_FRAGMENT_INDEXES(sBlk.s.fragments);
63535b
-	long long fragment_table_index[indexes];
63535b
+	size_t bytes = SQUASHFS_FRAGMENT_BYTES(sBlk.s.fragments);
63535b
+	size_t indexes = SQUASHFS_FRAGMENT_INDEXES(sBlk.s.fragments);
63535b
+	long long *fragment_table_index;
63535b
 
63535b
 	TRACE("read_fragment_table: %d fragments, reading %d fragment indexes "
63535b
 		"from 0x%llx\n", sBlk.s.fragments, indexes,
63535b
@@ -44,6 +44,11 @@ int read_fragment_table_4(long long *directory_table_end)
63535b
 		return TRUE;
63535b
 	}
63535b
 
63535b
+	fragment_table_index = malloc(indexes*sizeof(long long));
63535b
+	if(fragment_table_index == NULL)
63535b
+		EXIT_UNSQUASH("read_fragment_table: failed to allocate "
63535b
+			"fragment table index\n");
63535b
+
63535b
 	fragment_table = malloc(bytes);
63535b
 	if(fragment_table == NULL)
63535b
 		EXIT_UNSQUASH("read_fragment_table: failed to allocate "