Skip to content

Commit

Permalink
file_iterator: always map at least one block.
Browse files Browse the repository at this point in the history
Desired size of 0 would result in a noop for uncompressed blocks,
resulting in inconsistend behavior depending whether the block is
compressed, which ignores the desired size, or uncompressed, which
honors the desired size.
  • Loading branch information
Gottox committed Aug 20, 2023
1 parent 83bde94 commit a51cb8b
Showing 1 changed file with 8 additions and 7 deletions.
15 changes: 8 additions & 7 deletions lib/file/file_iterator.c
Original file line number Diff line number Diff line change
Expand Up @@ -141,13 +141,6 @@ map_block_uncompressed(
uint64_t outer_size = 0;
const size_t remaining_direct = sqsh__map_reader_remaining_direct(reader);

// Always try do map at least one block. This is needed for consistent
// behavior between implementations that ignore desired_size and
// implementations that honor it.
if (desired_size == 0) {
desired_size = 1;
}

for (; iterator->sparse_size == 0 && block_index < block_count;
block_index++) {
if (sqsh_file_block_is_compressed(file, block_index)) {
Expand Down Expand Up @@ -280,6 +273,14 @@ sqsh_file_iterator_next(

sqsh__extract_view_cleanup(&iterator->extract_view);

// Desired size of 0 would result in a noop for uncompressed blocks,
// resulting in inconsistend behavior depending whether the block is
// compressed, which ignores the desired size, or uncompressed, which
// honors the desired size.
if (desired_size == 0) {
desired_size = 1;
}

if (iterator->sparse_size > 0) {
return map_zero_block(iterator);
} else if (iterator->block_index < block_count) {
Expand Down

0 comments on commit a51cb8b

Please sign in to comment.