From: Michihiro NAKAJIMA Date: Thu, 11 Feb 2010 05:50:35 +0000 (-0500) Subject: The last sparse block info must reach the end of file. X-Git-Tag: v3.0.0a~1266 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=ea455cd24c1e3da703724925afa7b91753579faf;p=thirdparty%2Flibarchive.git The last sparse block info must reach the end of file. SVN-Revision: 1894 --- diff --git a/libarchive/archive_write_set_format_pax.c b/libarchive/archive_write_set_format_pax.c index 892295467..420a018f6 100644 --- a/libarchive/archive_write_set_format_pax.c +++ b/libarchive/archive_write_set_format_pax.c @@ -497,6 +497,21 @@ archive_write_pax_header(struct archive_write *a, sparse_count = archive_entry_sparse_reset(entry_main); else sparse_count = 0; + if (sparse_count) { + int64_t offset, length, last_offset = 0; + /* Get the last entry of sparse block. */ + while (archive_entry_sparse_next( + entry_main, &offset, &length) == ARCHIVE_OK) + last_offset = offset + length; + + /* If the last sparse block does not reach the end of file, + * We have to add a empty sparse block as the last entry to + * manage storing file data. */ + if (last_offset < archive_entry_size(entry_main)) + archive_entry_sparse_add_entry(entry_main, + archive_entry_size(entry_main), 0); + sparse_count = archive_entry_sparse_reset(entry_main); + } /* * First, check the name fields and see if any of them