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