]> git.ipfire.org Git - thirdparty/libarchive.git/commit
Fix sparse file offset overflow on 32-bit systems 1260/head
authorDaniel Verkamp <dverkamp@chromium.org>
Fri, 4 Oct 2019 19:31:32 +0000 (12:31 -0700)
committerDaniel Verkamp <dverkamp@chromium.org>
Fri, 4 Oct 2019 23:41:01 +0000 (16:41 -0700)
commite9f5e7081c62a47fb875569403e37cacca26dc12
treeb5242099c5ff98332be1074d4b80b168ee96bc0b
parentebef6c495e8d843523503a42c406fc5ff3ef8914
Fix sparse file offset overflow on 32-bit systems

On architectures where ssize_t is 32 bits but file offsets are 64 bits
(such as 32-bit Linux with _FILE_OFFSET_BITS=64), the POSIX disk reader
would incorrectly skip large sparse regions due to a 32-bit integer
overflow in _archive_read_data_block().  This can result in the reader
failing with "Encountered out-of-order sparse blocks", since the
overflowed value is interpreted as a signed number and added to the
current offset.

The bytes variable was used to store the difference between two 64-bit
integers, but bytes is a ssize_t.  Since this value of bytes was not
used after the block handling sparse offsets (it is always overwritten
in the block below), replace it with an int64_t sparse_bytes variable
that can always represent the difference without truncation.

Signed-off-by: Daniel Verkamp <dverkamp@chromium.org>
libarchive/archive_read_disk_posix.c
libarchive/test/test_sparse_basic.c