-
-
Notifications
You must be signed in to change notification settings - Fork 244
Fix unhandled exceptions from malformed expression strings #974
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 4 commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
7313485
Initial plan
Copilot 7cec935
Fix 5 unhandled exceptions from malformed expression strings (Issue #…
Copilot dcf03fb
Address code review: fix generic type accessibility check and use Has…
Copilot fb605bf
Remove accidentally committed .nuget/nuget.exe binary
Copilot 2060e4d
Change IsTypePubliclyAccessible parameter from Type to TypeInfo
Copilot dbfe34d
fix
StefH File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -238,3 +238,4 @@ _Pvt_Extensions | |
| /coverage.xml | ||
| /dynamic-coverage-*.xml | ||
| /test/**/coverage.net8.0.opencover.xml | ||
| .nuget/ | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,115 @@ | ||
| using System.Linq.Dynamic.Core.Exceptions; | ||
| using FluentAssertions; | ||
| using Xunit; | ||
|
|
||
| namespace System.Linq.Dynamic.Core.Tests; | ||
|
|
||
| /// <summary> | ||
| /// Tests for Issue #973: Multiple unhandled exceptions from malformed expression strings (5 crash sites found via fuzzing). | ||
| /// All 5 bugs should throw <see cref="ParseException"/> instead of unhandled runtime exceptions. | ||
| /// </summary> | ||
| public partial class QueryableTests | ||
| { | ||
|
|
||
| /// <summary> | ||
| /// Bug 1: ParseStringLiteral IndexOutOfRangeException for empty single-quoted string literal ''. | ||
| /// </summary> | ||
| [Fact] | ||
| public void Issue973_Bug1_EmptyCharLiteral_ShouldThrowParseException() | ||
| { | ||
| // Arrange | ||
| var items = new[] { new { Id = 1, Name = "Alice" } }.AsQueryable(); | ||
|
|
||
| // Act | ||
| Action act = () => items.Where("''"); | ||
|
|
||
| // Assert | ||
| act.Should().Throw<ParseException>(); | ||
| } | ||
|
|
||
| /// <summary> | ||
| /// Bug 2: TryGenerateAndAlsoNotNullExpression IndexOutOfRangeException for malformed np() call. | ||
| /// </summary> | ||
| [Fact] | ||
| public void Issue973_Bug2_MalformedNpCall_ShouldThrowParseException() | ||
| { | ||
| // Arrange | ||
| var items = new[] { new { Id = 1, Name = "Alice" } }.AsQueryable(); | ||
|
|
||
| // Act | ||
| Action act = () => items.Where("-np(--9999999)9999T--99999999999)99999"); | ||
|
|
||
| // Assert | ||
| act.Should().Throw<ParseException>(); | ||
| } | ||
|
|
||
| /// <summary> | ||
| /// Bug 3: Compiled expression IndexOutOfRangeException for string indexer with out-of-bounds constant index. | ||
| /// </summary> | ||
| [Fact] | ||
| public void Issue973_Bug3_StringIndexerOutOfBounds_ShouldThrowParseException() | ||
| { | ||
| // Arrange | ||
| var items = new[] { new { Id = 1, Name = "Alice" } }.AsQueryable(); | ||
|
|
||
| // Act | ||
| Action act = () => items.OrderBy("\"ab\"[3]").ToList(); | ||
|
|
||
| // Assert | ||
| act.Should().Throw<ParseException>(); | ||
| } | ||
|
|
||
| /// <summary> | ||
| /// Bug 3 (valid case): String indexer with in-bounds index should work correctly. | ||
| /// </summary> | ||
| [Fact] | ||
| public void Issue973_Bug3_StringIndexerInBounds_ShouldWork() | ||
| { | ||
| // Arrange | ||
| var items = new[] { new { Id = 1, Name = "Alice" } }.AsQueryable(); | ||
|
|
||
| // Act - "ab"[0] = 'a', "ab"[1] = 'b' are valid | ||
| var result0 = items.OrderBy("\"ab\"[0]").ToList(); | ||
| var result1 = items.OrderBy("\"ab\"[1]").ToList(); | ||
|
|
||
| // Assert | ||
| result0.Should().HaveCount(1); | ||
| result1.Should().HaveCount(1); | ||
| } | ||
|
|
||
| /// <summary> | ||
| /// Bug 4: NullReferenceException in compiled Select projection with mismatched brace/paren in new(). | ||
| /// </summary> | ||
| [Fact] | ||
| public void Issue973_Bug4_MismatchedBraceInNewExpression_ShouldThrowParseException() | ||
| { | ||
| // Arrange | ||
| var items = new[] { new { Id = 1, Name = "Alice", Age = 30, Score = 85.5, Active = true } }.AsQueryable(); | ||
|
|
||
| // Act | ||
| Action act = () => items.Select("new(Name }. AgAkQ & 1111555555+55555-5555555+555555+55555-55555").ToDynamicList(); | ||
|
|
||
| // Assert | ||
| act.Should().Throw<ParseException>(); | ||
| } | ||
|
|
||
| /// <summary> | ||
| /// Bug 5: MethodAccessException from $ identifier in GroupBy due to duplicate property names. | ||
| /// </summary> | ||
| [Fact] | ||
| public void Issue973_Bug5_DollarIdentifierWithDuplicatePropertyNames_ShouldThrowParseException() | ||
| { | ||
| // Arrange | ||
| var items = new[] | ||
| { | ||
| new { Id = 1, Name = "Alice", Age = 30, Score = 85.5, Active = true }, | ||
| new { Id = 2, Name = "Bob", Age = 25, Score = 92.0, Active = false }, | ||
| }.AsQueryable(); | ||
|
|
||
| // Act | ||
| Action act = () => items.GroupBy("new($ as DoubleAge, Age + 2 as DoubleAge)").ToDynamicList(); | ||
|
|
||
| // Assert - duplicate property name 'DoubleAge' should cause a ParseException | ||
| act.Should().Throw<ParseException>(); | ||
| } | ||
| } |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.