Skip to content

Commit

Permalink
multiarc/libarch: avoid mtree format (fix elfmz#1887)
Browse files Browse the repository at this point in the history
  • Loading branch information
elfmz committed Oct 14, 2023
1 parent a3faf64 commit 27b3987
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 0 deletions.
8 changes: 8 additions & 0 deletions multiarc/src/formats/libarch/libarch_utils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,14 @@ LibArchOpenRead::LibArchOpenRead(const char *name, const char *cmd, const char *
}

_fmt = archive_format(_arc);
if (_fmt == ARCHIVE_FORMAT_MTREE && archive_filter_count(_arc) <= 1
&& !StrEndsBy(name, ".tree") && !StrEndsBy(name, ".mtree")) {
// https://github.com/elfmz/far2l/issues/1887
// https://github.com/libarchive/libarchive/issues/1051
EnsureClosed();
throw std::runtime_error("mtree avoided");
}

if (_fmt == ARCHIVE_FORMAT_RAW && _ae != nullptr) {
const char *name_part = strrchr(name, '/');
std::string arc_raw_name(name_part ? name_part + 1 : name);
Expand Down
11 changes: 11 additions & 0 deletions utils/include/utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,17 @@ template <class StrT>
return i;
}

template <class CharT>
size_t StrEndsBy(const CharT *haystack, const CharT *needle)
{
const size_t hl = tzlen(haystack);
const size_t l = tzlen(needle);
if (!l || hl < l)
return 0;

return memcmp(haystack + hl - l, needle, l * sizeof(CharT)) ? 0 : l;
}

template <class StrT>
size_t StrEndsBy(const StrT &haystack, const typename StrT::value_type *needle)
{
Expand Down

0 comments on commit 27b3987

Please sign in to comment.