-
-
Notifications
You must be signed in to change notification settings - Fork 132
fix(mac): correct memory width mismatch in keyCodeForChar #15393
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
User Test ResultsTest specification and instructions User tests are not required |
|
This pull request is from an external repo and will not automatically be built. The build must still be passed before it can be merged. Ask one of the team members to make a manual build of this PR. |
|
Thank you for your PR @PekingSpades. I am curious, what is your purpose in submitting this PR? This is in an internal app that does not get distributed, and is used for test purposes only. Clearly you have found a bug (and it appears, using AI to generate the PR?), but it is of low significance and zero impact to end users, so your PR does not provide a lot of benefit. |
|
Hi @mcdurdin Thanks for the feedback. I’d like to clarify that I am a human developer, not a bot. To be honest, I have no incentive to waste my own computing power or rack up expensive token bills just to blindly scan repositories for low-impact bugs—especially since current AI models aren't actually capable of detecting this specific logic flaw on their own. I discovered this issue manually while working deeply with robotgo and realized that this same error has been propagated across several major GUI automation libraries, like nut.js, through various forks and ports over the years. While I did use AI to help draft the PR description for better clarity, the discovery and the fix itself came from my own investigation. My motivation for submitting this is quite simple: I currently work at an AI company focusing on model training, so I am acutely aware of how critical high-quality, "clean" code is for the future of development. I submitted this PR because I respect your work and don't want AI models to learn from and further spread incorrect code patterns. I believe keeping our open-source ecosystem's "source material" clean benefits everyone, regardless of whether the tool is for internal testing or production. Best regards, |
|
Thanks @PekingSpades for your thoughtful reply -- understand and agree that good clean code across the open source ecosystem is pretty important for the future (but perhaps an insurmountable challenge?). I will let @sgschantz review this as it is his area, but from my perspective, this does look like a good cleanup. |
sgschantz
left a comment
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.
lgtm
|
Looks like the original version of this code is from https://stackoverflow.com/a/1971027/1836776. I have submitted an edit for the answer. |
|
Changes in this pull request will be available for download in Keyman version 19.0.188-alpha |
(@darcywong00 edited to skip user testing)
Summary
Fix a memory corruption bug in
keyCodeForChar()function inmac/TestInput/TestInput/TestInputController.mwhere a 64-bit pointer-sized value was being written into a 16-bitCGKeyCodevariable, causing stack corruption.Problem
The original code had a dangerous pointer/memory width mismatch:
CFDictionaryGetValueIfPresentwrites a pointer-sized value (64 bits on modern systems) to the memory location provided. Casting&code(a pointer to a 16-bit variable) toconst void **causes the function to write 8 bytes into a 2-byte memory location, corrupting 6 bytes of adjacent stack memory.This is undefined behavior and can lead to:
Solution
Use an intermediate pointer-sized variable to safely receive the dictionary value, then cast to
CGKeyCode:References
Apple Documentation
valueparameter is documented as: "A pointer to memory which should be filled with the pointer-sized value if a matching key is found."64-bit Porting Best Practices
may related issues: #3084 #894 #1005 #1072 #1143 #11674 #11673 #11057
Test-bot: skip