1 diff -aurp a/squashfs-tools/unsquash-1.c b/squashfs-tools/unsquash-1.c
2 --- a/squashfs-tools/unsquash-1.c 2014-09-18 20:16:18.000000000 -0600
3 +++ b/squashfs-tools/unsquash-1.c 2017-08-29 13:18:14.403020644 -0600
4 @@ -332,17 +332,19 @@ int read_uids_guids_1()
5 guid_table = uid_table + sBlk.no_uids;
8 - unsigned int suid_table[sBlk.no_uids + sBlk.no_guids];
9 + unsigned int* suid_table = malloc((sBlk.no_uids + sBlk.no_guids) * sizeof(unsigned int));
11 res = read_fs_bytes(fd, sBlk.uid_start, (sBlk.no_uids +
12 sBlk.no_guids) * sizeof(unsigned int), suid_table);
15 ERROR("read_uids_guids: failed to read uid/gid table"
19 SQUASHFS_SWAP_INTS_3(uid_table, suid_table,
20 sBlk.no_uids + sBlk.no_guids);
23 res = read_fs_bytes(fd, sBlk.uid_start, (sBlk.no_uids +
24 sBlk.no_guids) * sizeof(unsigned int), uid_table);
25 diff -aurp a/squashfs-tools/unsquash-2.c b/squashfs-tools/unsquash-2.c
26 --- a/squashfs-tools/unsquash-2.c 2014-09-18 20:16:18.000000000 -0600
27 +++ b/squashfs-tools/unsquash-2.c 2017-08-29 13:23:48.111321548 -0600
28 @@ -32,7 +32,7 @@ void read_block_list_2(unsigned int *blo
29 TRACE("read_block_list: blocks %d\n", blocks);
32 - unsigned int sblock_list[blocks];
33 + unsigned int* sblock_list = malloc(blocks*sizeof(unsigned int));
34 memcpy(sblock_list, block_ptr, blocks * sizeof(unsigned int));
35 SQUASHFS_SWAP_INTS_3(block_list, sblock_list, blocks);
37 @@ -45,7 +45,7 @@ int read_fragment_table_2(long long *dir
39 int bytes = SQUASHFS_FRAGMENT_BYTES_2(sBlk.s.fragments);
40 int indexes = SQUASHFS_FRAGMENT_INDEXES_2(sBlk.s.fragments);
41 - unsigned int fragment_table_index[indexes];
42 + unsigned int* fragment_table_index = malloc(indexes * sizeof(unsigned int));
44 TRACE("read_fragment_table: %d fragments, reading %d fragment indexes "
45 "from 0x%llx\n", sBlk.s.fragments, indexes,
46 @@ -53,6 +53,7 @@ int read_fragment_table_2(long long *dir
48 if(sBlk.s.fragments == 0) {
49 *directory_table_end = sBlk.s.fragment_table_start;
50 + free(fragment_table_index);
54 @@ -62,7 +63,7 @@ int read_fragment_table_2(long long *dir
58 - unsigned int sfragment_table_index[indexes];
59 + unsigned int* sfragment_table_index = malloc(indexes * sizeof(unsigned int));
61 res = read_fs_bytes(fd, sBlk.s.fragment_table_start,
62 SQUASHFS_FRAGMENT_INDEX_BYTES_2(sBlk.s.fragments),
63 @@ -70,10 +71,14 @@ int read_fragment_table_2(long long *dir
65 ERROR("read_fragment_table: failed to read fragment "
67 + free(sfragment_table_index);
68 + free(fragment_table_index);
71 SQUASHFS_SWAP_FRAGMENT_INDEXES_2(fragment_table_index,
72 sfragment_table_index, indexes);
74 + free(sfragment_table_index);
76 res = read_fs_bytes(fd, sBlk.s.fragment_table_start,
77 SQUASHFS_FRAGMENT_INDEX_BYTES_2(sBlk.s.fragments),
78 @@ -81,6 +86,7 @@ int read_fragment_table_2(long long *dir
80 ERROR("read_fragment_table: failed to read fragment "
82 + free(fragment_table_index);
86 @@ -96,6 +102,7 @@ int read_fragment_table_2(long long *dir
88 ERROR("read_fragment_table: failed to read fragment "
90 + free(fragment_table_index);
94 @@ -111,6 +118,7 @@ int read_fragment_table_2(long long *dir
97 *directory_table_end = fragment_table_index[0];
98 + free(fragment_table_index);
102 diff -aurp a/squashfs-tools/unsquash-3.c b/squashfs-tools/unsquash-3.c
103 --- a/squashfs-tools/unsquash-3.c 2014-09-18 20:16:18.000000000 -0600
104 +++ b/squashfs-tools/unsquash-3.c 2017-08-29 14:43:17.016089289 -0600
105 @@ -32,7 +32,7 @@ int read_fragment_table_3(long long *dir
107 int bytes = SQUASHFS_FRAGMENT_BYTES_3(sBlk.s.fragments);
108 int indexes = SQUASHFS_FRAGMENT_INDEXES_3(sBlk.s.fragments);
109 - long long fragment_table_index[indexes];
110 + long long* fragment_table_index = malloc(indexes * sizeof(long long));
112 TRACE("read_fragment_table: %d fragments, reading %d fragment indexes "
113 "from 0x%llx\n", sBlk.s.fragments, indexes,
114 @@ -40,6 +40,7 @@ int read_fragment_table_3(long long *dir
116 if(sBlk.s.fragments == 0) {
117 *directory_table_end = sBlk.s.fragment_table_start;
118 + free(fragment_table_index);
122 @@ -49,7 +50,7 @@ int read_fragment_table_3(long long *dir
126 - long long sfragment_table_index[indexes];
127 + long long* sfragment_table_index = malloc(indexes * sizeof(long long));
129 res = read_fs_bytes(fd, sBlk.s.fragment_table_start,
130 SQUASHFS_FRAGMENT_INDEX_BYTES_3(sBlk.s.fragments),
131 @@ -57,10 +58,13 @@ int read_fragment_table_3(long long *dir
133 ERROR("read_fragment_table: failed to read fragment "
135 + free(fragment_table_index);
136 + free(sfragment_table_index);
139 SQUASHFS_SWAP_FRAGMENT_INDEXES_3(fragment_table_index,
140 sfragment_table_index, indexes);
141 + free(sfragment_table_index);
143 res = read_fs_bytes(fd, sBlk.s.fragment_table_start,
144 SQUASHFS_FRAGMENT_INDEX_BYTES_3(sBlk.s.fragments),
145 @@ -68,6 +72,7 @@ int read_fragment_table_3(long long *dir
147 ERROR("read_fragment_table: failed to read fragment "
149 + free(fragment_table_index);
153 @@ -83,6 +88,7 @@ int read_fragment_table_3(long long *dir
154 if(length == FALSE) {
155 ERROR("read_fragment_table: failed to read fragment "
157 + free(fragment_table_index);
161 @@ -98,6 +104,7 @@ int read_fragment_table_3(long long *dir
164 *directory_table_end = fragment_table_index[0];
165 + free(fragment_table_index);
169 diff -aurp a/squashfs-tools/unsquash-4.c b/squashfs-tools/unsquash-4.c
170 --- a/squashfs-tools/unsquash-4.c 2014-09-18 20:16:18.000000000 -0600
171 +++ b/squashfs-tools/unsquash-4.c 2017-08-29 14:49:01.424441708 -0600
172 @@ -33,7 +33,7 @@ int read_fragment_table_4(long long *dir
174 int bytes = SQUASHFS_FRAGMENT_BYTES(sBlk.s.fragments);
175 int indexes = SQUASHFS_FRAGMENT_INDEXES(sBlk.s.fragments);
176 - long long fragment_table_index[indexes];
177 + long long* fragment_table_index = malloc(indexes * sizeof(long long));
179 TRACE("read_fragment_table: %d fragments, reading %d fragment indexes "
180 "from 0x%llx\n", sBlk.s.fragments, indexes,
181 @@ -41,6 +41,7 @@ int read_fragment_table_4(long long *dir
183 if(sBlk.s.fragments == 0) {
184 *directory_table_end = sBlk.s.fragment_table_start;
185 + free(fragment_table_index);
189 @@ -55,6 +56,7 @@ int read_fragment_table_4(long long *dir
191 ERROR("read_fragment_table: failed to read fragment table "
193 + free(fragment_table_index);
196 SQUASHFS_INSWAP_FRAGMENT_INDEXES(fragment_table_index, indexes);
197 @@ -70,6 +72,7 @@ int read_fragment_table_4(long long *dir
198 if(length == FALSE) {
199 ERROR("read_fragment_table: failed to read fragment "
201 + free(fragment_table_index);
205 @@ -78,6 +81,7 @@ int read_fragment_table_4(long long *dir
206 SQUASHFS_INSWAP_FRAGMENT_ENTRY(&fragment_table[i]);
208 *directory_table_end = fragment_table_index[0];
209 + free(fragment_table_index);
213 @@ -356,13 +360,14 @@ int read_uids_guids_4()
215 int bytes = SQUASHFS_ID_BYTES(sBlk.s.no_ids);
216 int indexes = SQUASHFS_ID_BLOCKS(sBlk.s.no_ids);
217 - long long id_index_table[indexes];
218 + long long* id_index_table = malloc(indexes * sizeof(long long));
220 TRACE("read_uids_guids: no_ids %d\n", sBlk.s.no_ids);
222 id_table = malloc(bytes);
223 if(id_table == NULL) {
224 ERROR("read_uids_guids: failed to allocate id table\n");
225 + free(id_index_table);
229 @@ -370,6 +375,7 @@ int read_uids_guids_4()
230 SQUASHFS_ID_BLOCK_BYTES(sBlk.s.no_ids), id_index_table);
232 ERROR("read_uids_guids: failed to read id index table\n");
233 + free(id_index_table);
236 SQUASHFS_INSWAP_ID_BLOCKS(id_index_table, indexes);
237 @@ -382,11 +388,13 @@ int read_uids_guids_4()
239 ERROR("read_uids_guids: failed to read id table block"
241 + free(id_index_table);
246 SQUASHFS_INSWAP_INTS(id_table, sBlk.s.no_ids);
248 + free(id_index_table);
251 diff -aurp a/squashfs-tools/unsquashfs.c b/squashfs-tools/unsquashfs.c
252 --- a/squashfs-tools/unsquashfs.c 2017-08-29 14:58:51.917037533 -0600
253 +++ b/squashfs-tools/unsquashfs.c 2017-08-29 13:14:03.082818149 -0600
254 @@ -691,7 +691,7 @@ int read_block(int fd, long long start,
258 - char buffer[c_byte];
259 + char* buffer = malloc(c_byte);
262 res = read_fs_bytes(fd, start + offset, c_byte, buffer);
263 @@ -704,8 +704,10 @@ int read_block(int fd, long long start,
265 ERROR("%s uncompress failed with error code %d\n",
272 res = read_fs_bytes(fd, start + offset, c_byte, block);
274 @@ -2097,7 +2099,7 @@ void *writer(void *arg)
276 void *inflator(void *arg)
278 - char tmp[block_size];
279 + char* tmp = malloc(block_size);
282 struct cache_entry *entry = queue_get(to_inflate);
283 @@ -2120,6 +2122,7 @@ void *inflator(void *arg)
285 cache_block_ready(entry, res == -1);
291 diff -aurp a/squashfs-tools/mksquashfs.c b/squashfs-tools/mksquashfs.c
292 --- a/squashfs-tools/mksquashfs.c 2017-09-05 15:09:19.090937121 -0600
293 +++ b/squashfs-tools/mksquashfs.c 2017-09-01 09:58:11.274529037 -0600
294 @@ -652,7 +652,7 @@ long long write_directories()
295 long long write_id_table()
297 unsigned int id_bytes = SQUASHFS_ID_BYTES(id_count);
298 - unsigned int p[id_count];
299 + unsigned int* p = malloc(id_count * sizeof(unsigned int));
302 TRACE("write_id_table: ids %d, id_bytes %d\n", id_count, id_bytes);
303 @@ -655,6 +655,9 @@ long long write_id_table()
304 unsigned int* p = malloc(id_count * sizeof(unsigned int));
310 TRACE("write_id_table: ids %d, id_bytes %d\n", id_count, id_bytes);
311 for(i = 0; i < id_count; i++) {
312 TRACE("write_id_table: id index %d, id %d", i, id_table[i]->id);
314 @@ -661,6 +661,7 @@ long long write_id_table()
315 SQUASHFS_SWAP_INTS(&id_table[i]->id, p + i, 1);
319 return generic_write_table(id_bytes, p, 0, NULL, noI);
322 diff -aurp a/squashfs-tools/read_fs.c b/squashfs-tools/read_fs.c
323 --- a/squashfs-tools/read_fs.c 2014-09-18 20:16:18.000000000 -0600
324 +++ b/squashfs-tools/read_fs.c 2017-09-05 15:35:19.328547536 -0600
325 @@ -77,18 +77,24 @@ int read_block(int fd, long long start,
329 - char buffer[c_byte];
330 + char* buffer = malloc(c_byte);
336 res = read_fs_bytes(fd, start + 2, c_byte, buffer);
343 res = compressor_uncompress(comp, block, buffer, c_byte,
346 ERROR("%s uncompress failed with error code %d\n",
352 @@ -699,7 +705,7 @@ all_done:
353 unsigned int *read_id_table(int fd, struct squashfs_super_block *sBlk)
355 int indexes = SQUASHFS_ID_BLOCKS(sBlk->no_ids);
356 - long long index[indexes];
358 int bytes = SQUASHFS_ID_BYTES(sBlk->no_ids);
359 unsigned int *id_table;
361 @@ -708,12 +714,17 @@ unsigned int *read_id_table(int fd, stru
365 + index = malloc(indexes * sizeof(long long));
369 res = read_fs_bytes(fd, sBlk->id_table_start,
370 SQUASHFS_ID_BLOCK_BYTES(sBlk->no_ids), index);
372 ERROR("Failed to read id table index\n");
373 ERROR("Filesystem corrupted?\n");
379 @@ -732,6 +743,7 @@ unsigned int *read_id_table(int fd, stru
380 "length %d\n", i, index[i], length);
381 ERROR("Filesystem corrupted?\n");
387 @@ -753,14 +765,19 @@ int read_fragment_table(int fd, struct s
389 int bytes = SQUASHFS_FRAGMENT_BYTES(sBlk->fragments);
390 int indexes = SQUASHFS_FRAGMENT_INDEXES(sBlk->fragments);
391 - long long fragment_table_index[indexes];
392 + long long* fragment_table_index = malloc(indexes * sizeof(long long));
394 + if(fragment_table_index == NULL)
397 TRACE("read_fragment_table: %d fragments, reading %d fragment indexes "
398 "from 0x%llx\n", sBlk->fragments, indexes,
399 sBlk->fragment_table_start);
401 - if(sBlk->fragments == 0)
402 + if(sBlk->fragments == 0) {
403 + free(fragment_table_index);
407 *fragment_table = malloc(bytes);
408 if(*fragment_table == NULL)
409 @@ -773,6 +790,7 @@ int read_fragment_table(int fd, struct s
410 ERROR("Failed to read fragment table index\n");
411 ERROR("Filesystem corrupted?\n");
412 free(*fragment_table);
413 + free(fragment_table_index);
417 @@ -792,6 +810,7 @@ int read_fragment_table(int fd, struct s
418 fragment_table_index[i], length);
419 ERROR("Filesystem corrupted?\n");
420 free(*fragment_table);
421 + free(fragment_table_index);
425 @@ -799,6 +818,7 @@ int read_fragment_table(int fd, struct s
426 for(i = 0; i < sBlk->fragments; i++)
427 SQUASHFS_INSWAP_FRAGMENT_ENTRY(&(*fragment_table)[i]);
429 + free(fragment_table_index);
433 @@ -808,11 +828,16 @@ int read_inode_lookup_table(int fd, stru
435 int lookup_bytes = SQUASHFS_LOOKUP_BYTES(sBlk->inodes);
436 int indexes = SQUASHFS_LOOKUP_BLOCKS(sBlk->inodes);
437 - long long index[indexes];
438 + long long* index = malloc(indexes * sizeof(long long));
441 - if(sBlk->lookup_table_start == SQUASHFS_INVALID_BLK)
445 + if(sBlk->lookup_table_start == SQUASHFS_INVALID_BLK) {
450 *inode_lookup_table = malloc(lookup_bytes);
451 if(*inode_lookup_table == NULL)
452 @@ -824,6 +849,7 @@ int read_inode_lookup_table(int fd, stru
453 ERROR("Failed to read inode lookup table index\n");
454 ERROR("Filesystem corrupted?\n");
455 free(*inode_lookup_table);
460 @@ -843,12 +869,14 @@ int read_inode_lookup_table(int fd, stru
462 ERROR("Filesystem corrupted?\n");
463 free(*inode_lookup_table);
469 SQUASHFS_INSWAP_LONG_LONGS(*inode_lookup_table, sBlk->inodes);