Skip to content

Fix bug with traversing extracted packages when cleaning tarballs - #4353

Open
mikemhenry wants to merge 7 commits into
mamba-org:mainfrom
mikemhenry:fix-recursive-pkg-traversal
Open

Fix bug with traversing extracted packages when cleaning tarballs#4353
mikemhenry wants to merge 7 commits into
mamba-org:mainfrom
mikemhenry:fix-recursive-pkg-traversal

Conversation

@mikemhenry

@mikemhenry mikemhenry commented Jul 21, 2026

Copy link
Copy Markdown
Contributor

Description

Fixes this bug reported here: conda-forge/ambertools-feedstock#193

tl;dr when cleaning up tarballs, the code descends into extracted packages and gets confused when it finds things that look like tarballs or .conda packages. This PR adds some safeguards + a test for this bug.

Type of Change

  • Bugfix
  • Feature / enhancement
  • CI / Documentation
  • Maintenance

Checklist

  • My code follows the general style and conventions of the codebase, ensuring consistency
  • I have performed a self-review of my code
  • I have commented my code, particularly in hard-to-understand areas
  • My changes generate no new warnings
  • I have run pre-commit run --all locally in the source folder and confirmed that there are no linter errors.
  • I have added tests that prove my fix is effective or that my feature works
  • New and existing tests pass locally with my changes

@github-actions github-actions Bot added the release::bug_fixes For PRs fixing bugs label Jul 21, 2026
Comment thread libmamba/src/api/clean.cpp Outdated
@mikemhenry

Copy link
Copy Markdown
Contributor Author

Hmm,

linux-64

[166/166] Linking CXX executable micromamba/micromamba
FAILED: [code=1] micromamba/micromamba 
: && $BUILD_PREFIX/bin/x86_64-conda-linux-gnu-c++ -fvisibility-inlines-hidden -fmessage-length=0 -march=nocona -mtune=haswell -ftree-vectorize -fPIC -fstack-protector-strong -fno-plt -O2 -ffunction-sections -pipe -fno-merge-constants -isystem $PREFIX/include -fdebug-prefix-map=$SRC_DIR=/usr/local/src/conda/micromamba-2.5.0 -fdebug-prefix-map=$PREFIX=/usr/local/src/conda-prefix -fno-merge-constants -D_LIBCPP_DISABLE_AVAILABILITY=1 -O3 -DNDEBUG -Wl,-O2 -Wl,--sort-common -Wl,--as-needed -Wl,-z,relro -Wl,-z,now -Wl,--disable-new-dtags -Wl,--gc-sections -Wl,--allow-shlib-undefined -Wl,-rpath,$PREFIX/lib -Wl,-rpath-link,$PREFIX/lib -L$PREFIX/lib    -static-libstdc++ -static-libgcc -Wl,--dependency-file=micromamba/CMakeFiles/micromamba.dir/link.d micromamba/CMakeFiles/micromamba.dir/src/activate.cpp.o micromamba/CMakeFiles/micromamba.dir/src/clean.cpp.o micromamba/CMakeFiles/micromamba.dir/src/common_options.cpp.o micromamba/CMakeFiles/micromamba.dir/src/completer.cpp.o micromamba/CMakeFiles/micromamba.dir/src/config.cpp.o micromamba/CMakeFiles/micromamba.dir/src/constructor.cpp.o micromamba/CMakeFiles/micromamba.dir/src/create.cpp.o micromamba/CMakeFiles/micromamba.dir/src/env.cpp.o micromamba/CMakeFiles/micromamba.dir/src/info.cpp.o micromamba/CMakeFiles/micromamba.dir/src/install.cpp.o micromamba/CMakeFiles/micromamba.dir/src/list.cpp.o micromamba/CMakeFiles/micromamba.dir/src/login.cpp.o micromamba/CMakeFiles/micromamba.dir/src/main.cpp.o micromamba/CMakeFiles/micromamba.dir/src/package.cpp.o micromamba/CMakeFiles/micromamba.dir/src/remove.cpp.o micromamba/CMakeFiles/micromamba.dir/src/repoquery.cpp.o micromamba/CMakeFiles/micromamba.dir/src/run.cpp.o micromamba/CMakeFiles/micromamba.dir/src/shell.cpp.o micromamba/CMakeFiles/micromamba.dir/src/umamba.cpp.o micromamba/CMakeFiles/micromamba.dir/src/update.cpp.o micromamba/CMakeFiles/micromamba.dir/src/version.cpp.o -o micromamba/micromamba  $PREFIX/lib/libreproc.a  $PREFIX/lib/libreproc++.a  libmamba/libmamba.a  $PREFIX/lib/libreproc.a  libmamba/libmamba.a  $PREFIX/lib/libyaml-cpp.a  $PREFIX/lib/libmsgpack-c.a  $PREFIX/lib/libreproc++.a  $PREFIX/lib/libreproc.a  $PREFIX/lib/libsimdjson_static.a  $PREFIX/lib/libsolv.a  $PREFIX/lib/libsolvext.a  $PREFIX/lib/libcurl.a  $PREFIX/lib/libssh2.a  $PREFIX/lib/libgssapi_krb5.a  $PREFIX/lib/libkrb5.a  $PREFIX/lib/libk5crypto.a  $PREFIX/lib/libkrb5support.a  $PREFIX/lib/libcom_err.a  $PREFIX/lib/libssl.a  $PREFIX/lib/libcrypto.a  $PREFIX/lib/libarchive.a  $PREFIX/lib/libbz2.a  $PREFIX/lib/liblz4.a  $PREFIX/lib/libzstd.a  $PREFIX/lib/libz.a  $PREFIX/lib/liblzma.a  $PREFIX/lib/libnghttp2.a  $PREFIX/lib/libmsgpack-c.a  -lrt  -ldl  -lresolv  -lpthread  $PREFIX/lib/libfmt.so.12.1.0 && :
$BUILD_PREFIX/bin/x86_64-conda-linux-gnu-ld: $PREFIX/lib/libcurl.a(libcurl_la-psl.o): in function `Curl_psl_destroy':
psl.c:(.text.Curl_psl_destroy+0x22): undefined reference to `psl_free'
$BUILD_PREFIX/bin/x86_64-conda-linux-gnu-ld: $PREFIX/lib/libcurl.a(libcurl_la-psl.o): in function `Curl_psl_use':
psl.c:(.text.Curl_psl_use+0xcd): undefined reference to `psl_latest'
$BUILD_PREFIX/bin/x86_64-conda-linux-gnu-ld: psl.c:(.text.Curl_psl_use+0x109): undefined reference to `psl_free'
$BUILD_PREFIX/bin/x86_64-conda-linux-gnu-ld: psl.c:(.text.Curl_psl_use+0x15c): undefined reference to `psl_builtin'
$BUILD_PREFIX/bin/x86_64-conda-linux-gnu-ld: $PREFIX/lib/libcurl.a(libcurl_la-version.o): in function `curl_version':
version.c:(.text.curl_version+0xf0): undefined reference to `psl_check_version_number'
$BUILD_PREFIX/bin/x86_64-conda-linux-gnu-ld: $PREFIX/lib/libcurl.a(libcurl_la-cookie.o): in function `Curl_cookie_add':
cookie.c:(.text.Curl_cookie_add+0x571): undefined reference to `psl_is_cookie_domain_acceptable'
collect2: error: ld returned 1 exit status

osx-64

Undefined symbols for architecture x86_64:
  "_psl_builtin", referenced from:
      _Curl_psl_use in libcurl.a(libcurl_la-psl.o)
  "_psl_check_version_number", referenced from:
      _curl_version in libcurl.a(libcurl_la-version.o)
  "_psl_free", referenced from:
      _Curl_psl_destroy in libcurl.a(libcurl_la-psl.o)
      _Curl_psl_use in libcurl.a(libcurl_la-psl.o)
  "_psl_is_cookie_domain_acceptable", referenced from:
      _is_public_suffix in libcurl.a(libcurl_la-cookie.o)
  "_psl_latest", referenced from:
      _Curl_psl_use in libcurl.a(libcurl_la-psl.o)
ld: symbol(s) not found for architecture x86_64
x86_64-apple-darwin13.4: error: linker command failed with exit code 1 (use -v to see invocation)

@mikemhenry

Copy link
Copy Markdown
Contributor Author

It looks like those same CI errors pop up in other PRs and don't look related to the work done in this one -- are these failures known?

@mikemhenry

Copy link
Copy Markdown
Contributor Author

Ah looks like this will fix that issue conda-forge/micromamba-feedstock#304

@jjerphan jjerphan left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for your contribution.

I have a few comments, and we need to elucidate the change of symlink on other platforms.

Comment thread libmamba/src/api/clean.cpp Outdated
Comment thread libmamba/src/api/clean.cpp Outdated
Comment thread libmamba/src/api/clean.cpp Outdated
Comment thread micromamba/tests/test_clean.py Outdated
@mikemhenry
mikemhenry requested a review from jjerphan July 28, 2026 21:43
Comment thread micromamba/tests/test_clean.py Outdated
# Creating symlinks may require elevated privileges on Windows, so the
# regular payload file above provides cross-platform coverage.
dangling_symlink = None
if os.name != "nt":

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: there must be some test utilities defined for detecting Windows.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I couldn't find anything, but now I'm using the same method from other tests: https://github.com/mamba-org/mamba/blob/main/micromamba/tests/helpers.py#L66

Comment thread libmamba/src/api/clean.cpp Outdated
continue;
}
if (!p.is_directory()
if (p.is_regular_file()

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

On Unix this means archive-named symlinks elsewhere in the package cache tree would no longer be removed unless they resolve as regular files. I think this can be a problem.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good point, I’ll restore the !is_directory() condition

@mikemhenry
mikemhenry requested a review from jjerphan July 29, 2026 21:47
@jjerphan
jjerphan force-pushed the fix-recursive-pkg-traversal branch from 45bd819 to a0f9d5d Compare July 31, 2026 09:07
@codecov

codecov Bot commented Jul 31, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 0% with 2 lines in your changes missing coverage. Please review.
✅ Project coverage is 55.40%. Comparing base (af65e50) to head (69b197a).
⚠️ Report is 1 commits behind head on main.

Files with missing lines Patch % Lines
libmamba/src/api/clean.cpp 0.00% 2 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #4353      +/-   ##
==========================================
- Coverage   55.41%   55.40%   -0.01%     
==========================================
  Files         243      243              
  Lines       30382    30383       +1     
  Branches     3256     3256              
==========================================
  Hits        16835    16835              
- Misses      13544    13545       +1     
  Partials        3        3              

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@mikemhenry

Copy link
Copy Markdown
Contributor Author

Wooo, nice to see CI this green 😎

@mikemhenry

Copy link
Copy Markdown
Contributor Author

I think is ready for another review :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

release::bug_fixes For PRs fixing bugs

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants