-
Notifications
You must be signed in to change notification settings - Fork 5.3k
Fix access violation in JIT when printing long string literals #122460
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
Conversation
|
Tagging subscribers to this area: @JulieLeeMSFT, @jakobbotsch |
Co-authored-by: jkotas <6668460+jkotas@users.noreply.github.com>
|
@dotnet/jit-contrib PTLA |
There was a problem hiding this comment.
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 fixes an access violation in the JIT when dumping debug output for string literals longer than 256 characters. The crash occurred because getStringLiteral returns the actual string length but only copies up to bufferSize characters into the buffer, and the code was passing the full (potentially truncated) length to convertUtf16ToUtf8ForPrinting, causing it to read beyond the buffer.
Key changes:
- Truncate the length parameter to
MAX_LITERAL_LENGTHbefore callingconvertUtf16ToUtf8ForPrintingineePrintStringLiteral - Document the return value semantics of
getStringLiteralto clarify it returns the actual string length (which may exceedbufferSize)
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
| src/coreclr/jit/eeinterface.cpp | Adds truncation of length to MAX_LITERAL_LENGTH before passing to convertUtf16ToUtf8ForPrinting to prevent buffer overrun |
| src/coreclr/inc/corinfo.h | Documents that getStringLiteral returns the actual string length, which may be larger than bufferSize |
Co-authored-by: jkotas <6668460+jkotas@users.noreply.github.com>
Co-authored-by: jkotas <6668460+jkotas@users.noreply.github.com>
Co-authored-by: jkotas <6668460+jkotas@users.noreply.github.com>
The JIT crashes with an access violation when dumping debug output for string literals longer than the buffer size.
getStringLiteralreturns the actual string length but only copies up tobufferSizecharacters. The code was passing the full length toconvertUtf16ToUtf8ForPrinting, causing it to read beyond the buffer.Changes:
MAX_LITERAL_LENGTHbefore callingconvertUtf16ToUtf8ForPrintingineePrintStringLiteralgetStringLiteralreturn value semantics: returns actual length, may exceedbufferSizeMAX_LITERAL_LENGTHfrom 256 to 50 characters (since only 50 characters are printed)dstbuffer toMAX_LITERAL_LENGTH * 3 + 1(151 bytes) to accommodate UTF-8 encoding where each UTF-16 character can expand to up to 3 UTF-8 bytesThis is a debug-only issue with no customer impact.
Original prompt
💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.