From ea455cd24c1e3da703724925afa7b91753579faf Mon Sep 17 00:00:00 2001 From: Michihiro NAKAJIMA Date: Thu, 11 Feb 2010 00:50:35 -0500 Subject: [PATCH] The last sparse block info must reach the end of file. SVN-Revision: 1894 --- libarchive/archive_write_set_format_pax.c | 15 +++++++++++++++ 1 file changed, 15 insertions(+) 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 -- 2.47.3