Skip to content

tarball: detect symlink cycles in extractFileFromTar#2232

Merged
Subserial merged 2 commits intogoogle:mainfrom
vnykmshr:fix-symlink-loop-crash
Mar 17, 2026
Merged

tarball: detect symlink cycles in extractFileFromTar#2232
Subserial merged 2 commits intogoogle:mainfrom
vnykmshr:fix-symlink-loop-crash

Conversation

@vnykmshr
Copy link
Copy Markdown
Contributor

extractFileFromTar follows symlinks by recursively calling itself with the link target, but doesn't track which paths it has already visited. A two-entry tar where manifest.json and config.json point at each other recurses until the goroutine stack hits ~1GB and the process crashes via runtime.abort().

This is reachable through tarball.Image(), tarball.ImageFromPath(), and the layer access methods -- basically anything that loads a Docker tarball. The fix passes a visited set through the recursive calls and returns an error when it sees a path twice.

extractFileFromTar follows symlink and hard link entries recursively without tracking visited paths. A tar containing a link cycle (e.g., manifest.json -> config.json -> manifest.json) causes unbounded recursion until goroutine stack exhaustion crashes the process.

Track visited paths during link resolution and return an error when a cycle is detected.
@vnykmshr vnykmshr force-pushed the fix-symlink-loop-crash branch from 47bc359 to ca49c05 Compare March 14, 2026 08:06
@Subserial Subserial merged commit f439624 into google:main Mar 17, 2026
17 checks passed
@codecov-commenter
Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 52.74%. Comparing base (8b3c303) to head (3d2261d).
⚠️ Report is 74 commits behind head on main.

❗ There is a different number of reports uploaded between BASE (8b3c303) and HEAD (3d2261d). Click for more details.

HEAD has 1 upload less than BASE
Flag BASE (8b3c303) HEAD (3d2261d)
2 1
Additional details and impacted files
@@             Coverage Diff             @@
##             main    #2232       +/-   ##
===========================================
- Coverage   71.67%   52.74%   -18.94%     
===========================================
  Files         123      164       +41     
  Lines        9935    11113     +1178     
===========================================
- Hits         7121     5861     -1260     
- Misses       2115     4546     +2431     
- Partials      699      706        +7     

☔ View full report in Codecov by Sentry.
📢 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.

@vnykmshr vnykmshr deleted the fix-symlink-loop-crash branch March 18, 2026 04:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants