Skip to content

fix: resolve CodeQL code quality findings - #70

Merged
framinosona merged 1 commit into
mainfrom
fix/code-quality-findings
Nov 22, 2026
Merged

framinosona merged 1 commit into
mainfrom
fix/code-quality-findings

Conversation

@framinosona

Copy link
Copy Markdown
Member

Summary

Triage of the open CodeQL code quality findings (65 across 8 rules). Six rules are addressed. Two are left as they are on purpose (see Why).

  • MoveManifestResourceToDirectory[Async] and the cache variants now reject a filename that has a directory part, and use Path.Join.
  • NumericRangeTools.GetRange (float/double): removed an unreachable zero-step guard, step is validated with IsFinite plus an epsilon check.
  • !x.HasValue instead of x.HasValue == false, OfType/Where instead of a foreach wrapping a single if.
  • Tests: dispose CancellationTokenSource, Path.Join, no bare catch, no ! on a null-initialised local.

Why

  • Path.Combine (21 findings): the 4 production calls were a real bug. A rooted filename made Path.Combine drop targetDirectory, and .. escaped it, so a caller-supplied name could write outside the target directory. The 17 test calls were noise and are switched for consistency.
  • Generic catch (8): the 4 in TaskExtensions are intentional (they forward every exception to the caller's callback or TaskCompletionSource) and are unchanged. The 4 in tests are fixed.
  • Not in this PR: one Constant condition finding could not be located from source alone, so it is still open.

Change Type

  • Feature
  • Bug fix
  • Refactor
  • Docs only
  • CI/build/tooling

Affected Areas

  • String / Numeric / Enum extensions
  • Collection extensions (Dictionary / List / Enumerable / ConcurrentDictionary)
  • Temporal extensions (DateTime / DateOnly / TimeOnly / TimeSpan)
  • Reflection / Assembly extensions
  • Comparison extensions
  • Tests
  • Docs

Behavior And Compatibility

  • Public API changed
  • Exception behavior changed
  • No externally visible behavior change

MoveManifestResourceToDirectory, MoveManifestResourceToDirectoryAsync, MoveManifestResourceToCache and MoveManifestResourceToCacheAsync now throw ArgumentException (parameter filename) when filename is empty, rooted, or contains a directory part such as sub/file.txt or ../x. Before, a rooted name wrote outside the target directory, and a name with a subfolder only worked if that subfolder already existed. Worth a line in the release notes. Signatures are unchanged.

Tests

  • Unit tests added/updated
  • Not applicable (explain)

482 tests pass locally (476 before, plus 6 covering the filename validation in the sync and async paths, including that nothing is written outside the target directory for a rooted name).

Documentation

  • README feature list updated
  • XML docs added/updated
  • Not applicable (explain)

Checklist

  • Commit messages follow Conventional Commits (type(scope): subject)
  • CI passes
  • Change is scoped to one logical unit of work

- AssemblyExtensions: reject a filename with a directory part. A rooted
  filename made Path.Combine drop targetDirectory, and ".." escaped it.
  Path.Join is used from there on.
- NumericRangeTools: drop the unreachable zero-step guard inside the range
  iterators and validate step with IsFinite plus an epsilon check.
- Replace "HasValue == false" with a negation in TaskExtensions and
  SemaphoreSlimExtensions.
- UriExtensions, StringExtensions: filter with OfType/Where instead of a
  foreach whose body is a single if.
- Tests: dispose CancellationTokenSource, use Path.Join, stop swallowing
  exceptions with a bare catch, avoid dereferencing a null-initialised
  local, and cover the new filename validation.
Copilot AI balanced review requested due to automatic review settings November 22, 2026 20:38
@github-actions

Copy link
Copy Markdown

Test Results

482 tests  +6   482 ✅ +6   3s ⏱️ -1s
  1 suites ±0     0 💤 ±0 
  1 files   ±0     0 ❌ ±0 

Results for commit e3265e1. ± Comparison against base commit 2263c84.

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.

🟡 Changes recommended

The filename check accepts "." and "..", allowing extraction to create directories before failing with IOException instead of the expected ArgumentException.

1 open issue
What changed in this PR

This PR addresses CodeQL quality findings in the .NET extension library, focusing on resource-extraction filename validation and targeted cleanup without changing public signatures.

Changes:

  • Validate extraction filenames, use Path.Join, and document the new exception behavior.
  • Simplify numeric step validation, nullable checks, and filtered loops.
  • Add filename-validation tests and improve test resource disposal and exception assertions.
File Description
Plugin.BaseTypeExtensions/​UriExtensions.cs Filter null query keys with OfType.
Plugin.BaseTypeExtensions/​TaskExtensions.cs Simplify nullable timeout checks.
Plugin.BaseTypeExtensions/​StringExtensions.cs Extract and apply the character-filter predicate.
Plugin.BaseTypeExtensions/​SemaphoreSlimExtensions.cs Simplify nullable timeout checks.
Plugin.BaseTypeExtensions/​NumericRangeTools.cs Consolidate floating-point step validation and remove redundant guards.
Plugin.BaseTypeExtensions/​AssemblyExtensions.cs Validate extraction filenames, use Path.Join, and update exception documentation.
Plugin.BaseTypeExtensions.Tests/​TaskExtensionsTests.cs Dispose cancellation sources and assert expected exceptions explicitly.
Plugin.BaseTypeExtensions.Tests/​SemaphoreSlimExtensionsTests.cs Dispose cancellation sources.
Plugin.BaseTypeExtensions.Tests/​ListExtensionsTests.cs Dispose the cancellation source.
Plugin.BaseTypeExtensions.Tests/​ExceptionExtensionsTests.cs Catch the specific expected exception.
Plugin.BaseTypeExtensions.Tests/​EnumerableExtensionsTests.cs Dispose the cancellation source.
Plugin.BaseTypeExtensions.Tests/​DictionaryExtensionsTests.cs Dispose the cancellation source.
Plugin.BaseTypeExtensions.Tests/​ConcurrentDictioneryExtensionsTests.cs Dispose cancellation sources and adjust null-test declarations.
Plugin.BaseTypeExtensions.Tests/​CancellationTokenExtensionsTests.cs Retain and dispose cancellation sources explicitly.
Plugin.BaseTypeExtensions.Tests/​AssemblyExtensionsTests.cs Add filename-rejection tests and switch path construction to Path.Join.

Review effort: Balanced

/// </summary>
private static void ThrowIfNotPlainFileName(string filename)
{
if (string.IsNullOrWhiteSpace(filename) || Path.GetFileName(filename) != filename)
@framinosona
framinosona merged commit cae9925 into main Nov 22, 2026
13 checks passed
@framinosona
framinosona deleted the fix/code-quality-findings branch November 22, 2026 20:45
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.

2 participants