Wed 16 Sep 2015 08:08:35 PM UTC, original submission:
If you have an archive and you update it and the update includes the last file in the archive, then that file is corrupted in the resulting archive.
Test case showing problem included.
This tiny patch solves the problem for me:
diff -urN fastjar-0.98/compress.c fastjar-0.98.fixed/compress.c
--- fastjar-0.98/compress.c 2008-10-15 17:25:36.000000000 +0000
+++ fastjar-0.98.fixed/compress.c 2015-09-16 19:46:59.600910166 +0000
@@ -86,6 +86,10 @@
exit(EXIT_FAILURE);
}
}
+ else if (!next && here + len >= end_of_entries)
+ {
+ end_of_entries = here + len;
+ }
}
return write (fd, buf, len);
I suspect adding the manifests might also have a problem (but I didn't test it) and might need something like this:
diff -urN fastjar-0.98/jartool.c fastjar-0.98.fixed/jartool.c
--- fastjar-0.98/jartool.c 2015-09-16 19:48:21.000000000 +0000
+++ fastjar-0.98.fixed/jartool.c 2015-09-16 19:49:36.006209825 +0000
@@ -1274,17 +1274,24 @@
compress_file(ffd, jfd, ze, existing);
} else {
/* If we are not writing the last entry, make space for it. */
- if (existing && existing->next_entry)
+ if (existing)
{
- if (ze->usize > existing->usize)
+ if (existing->next_entry)
{
- if (shift_down (jfd, existing->next_entry->offset,
- ze->usize - existing->usize, existing->next_entry))
+ if (ze->usize > existing->usize)
{
- fprintf (stderr, "%s: %s\n", progname, strerror (errno));
- return 1;
+ if (shift_down (jfd, existing->next_entry->offset,
+ ze->usize - existing->usize, existing->next_entry))
+ {
+ fprintf (stderr, "%s: %s\n", progname, strerror (errno));
+ return 1;
+ }
}
}
+ else
+ {
+ end_of_entries += (ze->usize - existing->usize);
+ }
}
/* Write the contents of the file (uncompressed) to the zip file */
|