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