Skip to content

Commit

Permalink
Fix BitNestedArchiveReader::items()
Browse files Browse the repository at this point in the history
  • Loading branch information
rikyoz committed Jun 15, 2024
1 parent 84ae9b3 commit 62c0616
Showing 1 changed file with 15 additions and 1 deletion.
16 changes: 15 additions & 1 deletion src/bitnestedarchivereader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,21 @@ auto BitNestedArchiveReader::items() const -> std::vector< BitArchiveItemInfo >
}

std::vector< BitArchiveItemInfo > result;
for ( std::uint32_t index = 0; index < std::numeric_limits< std::uint32_t >::max(); ++index ) {

/* The TAR format always reports std::numeric_limits< std::uint32_t >::max()
* as itemsCount() when the archive is opened sequentially.
* Other formats that support sequential opening only support single file compression.
* Therefore:
* - For TAR archives, we don't know the actual number of items in the archive,
* so we can't reserve space in the vector (as we do in BitArchiveReader::items()),
* and we stop when we encounter the first item not reporting the BitProperty::IsDir property.
* - For other archives, we stop when we reach itemsCount() (most likely one) items added to the vector. */
const auto itemsCount = mArchive.itemsCount();
if ( itemsCount < std::numeric_limits< std::uint32_t >::max() ) {
result.reserve( itemsCount );
}

for ( std::uint32_t index = 0; index < itemsCount; ++index ) {
if ( !mArchive.itemHasProperty( index, BitProperty::IsDir ) ) {
mLastReadItem = index;
return result;
Expand Down

0 comments on commit 62c0616

Please sign in to comment.