Skip to content

Commit a136438

Browse files
committed
Handle zip_stat_index() failure.
1 parent 9936160 commit a136438

File tree

1 file changed

+20
-11
lines changed

1 file changed

+20
-11
lines changed

src/zipcmp.c

Lines changed: 20 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -535,7 +535,7 @@ list_zip(const char *name, struct archive *a) {
535535
zip_t *za;
536536
int err;
537537
struct zip_stat st;
538-
unsigned int i;
538+
unsigned int i, j;
539539

540540
if ((za = zip_open(name, check_consistency ? ZIP_CHECKCONS : 0, &err)) == NULL) {
541541
zip_error_t error;
@@ -556,23 +556,30 @@ list_zip(const char *name, struct archive *a) {
556556
exit(1);
557557
}
558558

559+
j = 0;
559560
for (i = 0; i < a->nentry; i++) {
560-
zip_stat_index(za, i, 0, &st);
561-
a->entry[i].name = strdup(st.name);
562-
a->entry[i].size = st.size;
563-
a->entry[i].crc = st.crc;
561+
if (zip_stat_index(za, i, 0, &st) < 0) {
562+
fprintf(stderr, "%s: cannot stat file %u in zip archive '%s': %s\n", progname, i, name, zip_strerror(za));
563+
continue;
564+
}
565+
566+
a->entry[j].name = strdup(st.name);
567+
a->entry[j].size = st.size;
568+
a->entry[j].crc = st.crc;
564569
if (test_files)
565570
test_file(za, i, name, st.name, st.size, st.crc);
566571
if (paranoid) {
567-
a->entry[i].comp_method = st.comp_method;
568-
ef_read(za, i, a->entry + i);
569-
a->entry[i].comment = zip_file_get_comment(za, i, &a->entry[i].comment_length, 0);
572+
a->entry[j].comp_method = st.comp_method;
573+
ef_read(za, i, a->entry + j);
574+
a->entry[j].comment = zip_file_get_comment(za, i, &a->entry[j].comment_length, 0);
570575
}
571576
else {
572-
a->entry[i].comp_method = 0;
573-
a->entry[i].n_extra_fields = 0;
577+
a->entry[j].comp_method = 0;
578+
a->entry[j].n_extra_fields = 0;
574579
}
575-
a->entry[i].last_modification_time = st.mtime;
580+
a->entry[j].last_modification_time = st.mtime;
581+
582+
j++;
576583
}
577584

578585
if (paranoid) {
@@ -584,6 +591,8 @@ list_zip(const char *name, struct archive *a) {
584591
a->comment = NULL;
585592
a->comment_length = 0;
586593
}
594+
595+
a->nentry = j;
587596
}
588597

589598
return 0;

0 commit comments

Comments
 (0)