Skip to content

Fix exception check .NET 9#131079

Merged
alinpahontu2912 merged 1 commit into
dotnet:release/9.0-stagingfrom
alinpahontu2912:tar_test_9
Jul 22, 2026
Merged

Fix exception check .NET 9#131079
alinpahontu2912 merged 1 commit into
dotnet:release/9.0-stagingfrom
alinpahontu2912:tar_test_9

Conversation

@alinpahontu2912

@alinpahontu2912 alinpahontu2912 commented Jul 20, 2026

Copy link
Copy Markdown
Member

Fixes #131053

Customer Impact

Flaky tar tests.

Found internally - Windows symlinks are always created as files, not directories. Depending on the build, it can throw either during creation of a symlink that represents directory structure or when parsing it. This change fixes the flaky test.

Regression

Caused by earlier change in the area.

Testing

Reenabled failing CI tests.

Risk

Low.

@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines:
Successfully started running 3 pipeline(s).
13 pipeline(s) were filtered out due to trigger conditions.
There may be pipelines that require an authorized user to comment /azp run to run.

@dotnet-policy-service

Copy link
Copy Markdown
Contributor

Tagging subscribers to this area: @dotnet/area-system-io
See info in area-owners.md if you want to be subscribed.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

This PR updates a Windows-specific tar extraction test to tolerate OS/build-dependent exception behavior when extracting nested entries through a type-mismatched symlink (file symlink pointing at a directory), while still validating that directory traversal is rejected and nothing escapes the destination root.

Changes:

  • Broaden the Windows assertion to accept either UnauthorizedAccessException or IOException from TarFile.ExtractToDirectory.
  • Expand the test comment to document why different Windows builds surface different exception types for the same underlying scenario.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@github-actions

github-actions Bot commented Jul 20, 2026

Copy link
Copy Markdown
Contributor

Workflow state for the Holistic Review Orchestrator.

{
  "version": 5,
  "last_dispatched_commit": "47cc2b67251cdfdd1a9fb3ae6ef8552ace7bb72f",
  "last_dispatched_base_ref": "release/9.0-staging",
  "last_dispatched_base_sha": "89cb9dc4661289d4c86f514bbe8b9e4d12343b76",
  "last_reviewed_commit": "47cc2b67251cdfdd1a9fb3ae6ef8552ace7bb72f",
  "last_reviewed_base_ref": "release/9.0-staging",
  "last_reviewed_base_sha": "89cb9dc4661289d4c86f514bbe8b9e4d12343b76",
  "last_recorded_worker_run_id": "29747439062",
  "review_attempt_commit": "",
  "review_attempt_base_ref": "",
  "review_attempt_count": 0,
  "max_review_attempts": 5,
  "review_history_format": "holistic-review-disclosure-v1",
  "review_history": [
    {
      "commit": "47cc2b67251cdfdd1a9fb3ae6ef8552ace7bb72f",
      "review_id": 4735591453
    }
  ]
}

@github-actions github-actions Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Holistic Review

Motivation: Justified. The security-regression test ExtractToDirectory_RejectsChainedSymlinkDirectoryTraversal_WithNestedFile is flaky on Windows because a directory-targeted symlink is materialized as a file symlink (FileInfo.CreateAsSymbolicLink), so the rejection surfaces as either UnauthorizedAccessException (during ResolveLinkTarget in the traversal-safety walk) or IOException (creating a directory over the existing file symlink), depending on the OS build. Hard-asserting a single type produced spurious failures on the release/9.0-staging branch.

Approach: Sound. The change narrowly relaxes only the Windows branch to accept both exception types via Assert.ThrowsAny<Exception> plus an is IOException or UnauthorizedAccessException assertion, while preserving the strict Assert.Throws<IOException> on non-Windows. Crucially, the security invariant checks (outside/ directory and pwned.txt must not exist) are retained unchanged, so the test still verifies nothing escapes the destination regardless of which exception is thrown. Test-only, no product code touched.

Summary: ✅ LGTM. The relaxation is scoped to the platform-specific non-determinism and keeps the meaningful escape-prevention assertions intact, so it fixes the flakiness without weakening the regression's security guarantee. The failure message includes the unexpected exception ($"Unexpected exception type: {ex}") which aids future diagnosis.


Detailed Findings

✅ Test correctness — Escape guarantee preserved

The post-extraction assertions (lines 465–467) that outside/ and outside/pwned.txt are never created run on all platforms and are unchanged. This is the security-relevant part of the test; accepting a broader set of exception types on Windows does not weaken it because a successful traversal escape would still fail those checks.

💡 Optional — Slightly broader catch than necessary

Assert.ThrowsAny<Exception> accepts any exception and then re-validates the type. This is fine and arguably clearer given the explanatory comment, but the two acceptable types could equivalently be asserted directly. Not a blocker.

Note

This review was generated by this repository's Holistic Review agentic workflow to complement the built-in Copilot review.

Generated by Holistic Review · 55.2 AIC · ⌖ 10.5 AIC · ⊞ 10K

@alinpahontu2912

Copy link
Copy Markdown
Member Author

/ba-g test failures are unrelated to my change

@karelz karelz added this to the 9.0.x milestone Jul 22, 2026
@karelz karelz added the Servicing-approved Approved for servicing release label Jul 22, 2026
@karelz

karelz commented Jul 22, 2026

Copy link
Copy Markdown
Member

Test-only change, approved

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

Labels

area-System.IO Servicing-approved Approved for servicing release

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants