Skip to content

CodeQL ilasm fixes - #125152

Merged
dhartglassMSFT merged 9 commits into
dotnet:mainfrom
dhartglassMSFT:ilasm_codeQL1
Mar 16, 2026
Merged

dhartglassMSFT merged 9 commits into
dotnet:mainfrom
dhartglassMSFT:ilasm_codeQL1

Conversation

@dhartglassMSFT

@dhartglassMSFT dhartglassMSFT commented Mar 3, 2026 •

Copy link
Copy Markdown
Contributor

Fix two issues that got flagged

1 - Fix a mistyped loop counter.

2 - One of the files frequently casts CHAR*->WCHAR*. Retyping isn't reasonable, because these methods are called through function pointers using char*. These casts are probably safe since they all point into MapViewOfFile, but I add alignment constraints and bailouts if somehow we have an odd pointer. The analyzer still complains however, so I also need an explicit suppression of the warning.

I'm kicking off another analysis pipeline in a bit to make sure the suppressions get picked up

Copilot AI review requested due to automatic review settings March 3, 2026 23:10
@dotnet-policy-service

Copy link
Copy Markdown
Contributor

Tagging subscribers to this area: @JulieLeeMSFT, @dotnet/jit-contrib
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 targets CodeQL/static-analysis findings in the CoreCLR ilasm tool by addressing integer type correctness and potential unaligned UTF-16 access patterns in the parser/helpers.

Changes:

  • Use an unsigned 16-bit loop index when iterating metadata streams during PE file creation.
  • Avoid unaligned WCHAR* dereferences in SymW by reading via memcpy.
  • Add/adjust alignment handling for Unicode parsing helpers (aligned buffers; enforce even-byte lengths for UTF-16 token copies).

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.

File Description
src/coreclr/ilasm/writer.cpp Updates stream-iteration index type to avoid signed/size issues when walking metadata streams.
src/coreclr/ilasm/grammar_after.cpp Hardens Unicode parsing helpers against unaligned access and odd-length UTF-16 token handling (plus aligned scratch buffers).

Comment thread src/coreclr/ilasm/grammar_after.cpp Resolved
Comment thread src/coreclr/ilasm/grammar_after.cpp Resolved
@dhartglassMSFT
dhartglassMSFT marked this pull request as ready for review March 4, 2026 22:21
Copilot AI review requested due to automatic review settings March 4, 2026 22:21

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

Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.

Comment thread src/coreclr/ilasm/writer.cpp Resolved
Comment thread src/coreclr/ilasm/grammar_after.cpp Resolved
@dhartglassMSFT dhartglassMSFT changed the title [Draft] CodeQL ilasm fixes CodeQL ilasm fixes Mar 4, 2026
Copilot AI review requested due to automatic review settings March 4, 2026 22:29

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

Copilot reviewed 2 out of 2 changed files in this pull request and generated 3 comments.

Comment thread src/coreclr/ilasm/grammar_after.cpp Resolved
Comment thread src/coreclr/ilasm/grammar_after.cpp Resolved
Comment thread src/coreclr/ilasm/grammar_after.cpp Resolved
Comment thread src/coreclr/ilasm/grammar_after.cpp Resolved
Comment thread src/coreclr/ilasm/writer.cpp Resolved
Comment thread src/coreclr/ilasm/grammar_after.cpp Resolved
Copilot AI review requested due to automatic review settings March 5, 2026 00:53

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

Copilot reviewed 2 out of 2 changed files in this pull request and generated no new comments.

@am11

am11 commented Mar 5, 2026

Copy link
Copy Markdown
Member

I think focus should move to the managed ilasm in src/tools/ilasm, which will eventually make the native implementation obsolete.

@AaronRobinsonMSFT

Copy link
Copy Markdown
Member

I think focus should move to the managed ilasm in src/tools/ilasm, which will eventually make the native implementation obsolete.

Until that is working, which is a long ways off, we still need to satisfy tooling and all the requirements for the existing code.

@am11

am11 commented Mar 5, 2026

Copy link
Copy Markdown
Member

which is a long ways off,

It is just pending test infra support, everything else is in place; all TODOs addressed.

Copilot AI review requested due to automatic review settings March 9, 2026 20:26

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

Copilot reviewed 3 out of 3 changed files in this pull request and generated 2 comments.

Comment thread src/coreclr/ilasm/grammar_after.cpp Resolved
Comment thread src/coreclr/ilasm/grammar_after.cpp Resolved

@AaronRobinsonMSFT AaronRobinsonMSFT left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

:shipit:

Comment thread src/coreclr/ilasm/grammar_after.cpp Resolved
Copilot AI review requested due to automatic review settings March 10, 2026 21:00

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

Copilot reviewed 3 out of 3 changed files in this pull request and generated 3 comments.

Comment thread src/coreclr/ilasm/grammar_after.cpp Resolved
Comment thread src/coreclr/ilasm/grammar_after.cpp Resolved
Comment thread src/coreclr/ilasm/asmparse.h Resolved
@dhartglassMSFT
dhartglassMSFT enabled auto-merge (squash) March 10, 2026 21:18
@dhartglassMSFT
dhartglassMSFT merged commit 611b2cb into dotnet:main Mar 16, 2026
127 checks passed
@github-actions github-actions Bot locked and limited conversation to collaborators Apr 16, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants