From 1121ba704b6e9bf51233be6b43c2115445e989e7 Mon Sep 17 00:00:00 2001 From: Jeffrey Stuhr <110697945+fadwen@users.noreply.github.com> Date: Tue, 24 Nov 2026 16:54:37 -0800 Subject: [PATCH] fix(filter): read a version part too large for Int64 as no version Get-IslVersionPart accepted any number of digits in a part and cast it with [long], which throws on overflow, so a filter rule or a device version such as 10.0.99999999999999999999 ended Test-IntuneAssignmentFilter with a conversion error. Such a text is now not a version, like any other text the evaluator cannot order, and the ordering operators do not match it. Closes #106 --- CHANGELOG.md | 4 ++++ Private/Get-IslVersionPart.ps1 | 12 ++++++++++-- Tests/Unit/Private/Get-IslVersionPart.Tests.ps1 | 2 ++ .../Public/Test-IntuneAssignmentFilter.Tests.ps1 | 10 ++++++++++ 4 files changed, 26 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 54f612c..cc73acb 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -153,6 +153,10 @@ entries are carried over from the manifest's release notes. ### Fixed +- A version in an assignment filter with a part too large for a 64-bit number, such as + `10.0.99999999999999999999`, is not a version that `Test-IntuneAssignmentFilter` can order, so + `-gt`, `-ge`, `-lt` and `-le` on it do not match. It ended the command with a conversion + error (#106). - A `Severity` setting that is not a hashtable, such as `Severity = 'Error'` in a settings file or in `-Settings`, ends `Test-IntuneScript` with `SettingsInvalid` and a message that names the source. It ended with a strict-mode error, `PropertyNotFoundStrict`, that named neither the diff --git a/Private/Get-IslVersionPart.ps1 b/Private/Get-IslVersionPart.ps1 index 7cf7dd5..430049d 100644 --- a/Private/Get-IslVersionPart.ps1 +++ b/Private/Get-IslVersionPart.ps1 @@ -6,7 +6,8 @@ function Get-IslVersionPart { .DESCRIPTION A text of one to four numbers separated by dots, with white space around it allowed, gives four numbers, the parts that are missing as 0: '10.0.26100' gives 10, 0, 26100, 0. Any other - text is not a version, and gives nothing. + text is not a version, and gives nothing; so does a text with a part too large for a 64-bit + number, which has no order the comparison could use. .PARAMETER Text The text to read. @@ -34,7 +35,14 @@ function Get-IslVersionPart { return } $parts = [System.Collections.Generic.List[long]]::new() - foreach ($part in ($Text.Trim() -split '\.')) { $parts.Add([long]$part) } + foreach ($part in ($Text.Trim() -split '\.')) { + $number = [long]0 + $style = [System.Globalization.NumberStyles]::None + if (-not [long]::TryParse($part, $style, [cultureinfo]::InvariantCulture, [ref]$number)) { + return + } + $parts.Add($number) + } while ($parts.Count -lt 4) { $parts.Add(0) } $parts.ToArray() } diff --git a/Tests/Unit/Private/Get-IslVersionPart.Tests.ps1 b/Tests/Unit/Private/Get-IslVersionPart.Tests.ps1 index f4c6423..a41de1f 100644 --- a/Tests/Unit/Private/Get-IslVersionPart.Tests.ps1 +++ b/Tests/Unit/Private/Get-IslVersionPart.Tests.ps1 @@ -22,6 +22,7 @@ Describe 'Get-IslVersionPart' -Tag 'Unit', 'Private' { @{ Text = '10'; Expected = @(10, 0, 0, 0) } @{ Text = '10.0.26100'; Expected = @(10, 0, 26100, 0) } @{ Text = '10.0.26100.4202'; Expected = @(10, 0, 26100, 4202) } + @{ Text = '9223372036854775807'; Expected = @([long]::MaxValue, 0, 0, 0) } @{ Text = ' 6.3 '; Expected = @(6, 3, 0, 0) } ) { $parts = Get-Part -Text $Text @@ -38,6 +39,7 @@ Describe 'Get-IslVersionPart' -Tag 'Unit', 'Private' { @{ Text = '1.2.3.4.5' } @{ Text = '10.0.' } @{ Text = '-1.0' } + @{ Text = '10.0.99999999999999999999' } ) { Get-Part -Text $Text | Should-BeCollection @() } diff --git a/Tests/Unit/Public/Test-IntuneAssignmentFilter.Tests.ps1 b/Tests/Unit/Public/Test-IntuneAssignmentFilter.Tests.ps1 index 0aeb3dc..e3ba4f0 100644 --- a/Tests/Unit/Public/Test-IntuneAssignmentFilter.Tests.ps1 +++ b/Tests/Unit/Public/Test-IntuneAssignmentFilter.Tests.ps1 @@ -193,6 +193,16 @@ Describe 'Test-IntuneAssignmentFilter' -Tag 'Unit', 'Public' { $unequal.Matched | Should-BeTrue } + It 'treats a version with a part too large for a 64-bit number as never ordered' { + $device = @{ operatingSystemVersion = '10.0.22631' } + $rule = '(device.operatingSystemVersion -ge "10.0.99999999999999999999")' + $inRule = Test-IntuneAssignmentFilter -Rule $rule -Device $device + $inRule.Matched | Should-BeFalse + $huge = @{ operatingSystemVersion = '10.0.99999999999999999999' } + $onDevice = Test-IntuneAssignmentFilter -Rule '(device.operatingSystemVersion -lt 10.0)' -Device $huge + $onDevice.Matched | Should-BeFalse + } + It 'validates the syntax without a device on request' { $result = Test-IntuneAssignmentFilter -Rule '(device.cpuArchitecture -eq "x64")' -SyntaxOnly 3>$null $result.Matched | Should-BeNull