-
-
Notifications
You must be signed in to change notification settings - Fork 21.6k
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
Windows: Fix heap overflow setting native icon #71699
Windows: Fix heap overflow setting native icon #71699
Conversation
We really like more descriptive commit message in a codebase that gets a few dozen commits merged everyday :) Something like
would be perfect. |
OK will change commit msg |
b1cff06
to
a2c15c3
Compare
Updated commit msg |
Seems like this was fixed in |
@@ -3105,7 +3105,7 @@ void OS_Windows::set_native_icon(const String &p_filename) { | |||
pos += sizeof(WORD); | |||
f->seek(pos); | |||
|
|||
icon_dir = (ICONDIR *)memrealloc(icon_dir, 3 * sizeof(WORD) + icon_dir->idCount * sizeof(ICONDIRENTRY)); | |||
icon_dir = (ICONDIR *)memrealloc(icon_dir, sizeof(ICONDIR) + (icon_dir->idCount * sizeof(ICONDIRENTRY))); |
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.
In master
it is icon_dir = (ICONDIR *)memrealloc(icon_dir, sizeof(ICONDIR) - sizeof(ICONDIRENTRY) + icon_dir->idCount * sizeof(ICONDIRENTRY));
, (see #68631) which is probably correct since ICONDIR
already include the first entry.
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.
Sure, that saves sizeof(ICONDIRENTRY)
bytes
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.
Can idCount
ever be zero?
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.
Part of why I guess I didn't love subtracting that part of the struct size away... Was thinking better safe than sorry, as was unsure what valid range of idCount could be without any context of how icons worked.
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.
Can idCount ever be zero?
Technically yes (in practice no, icon file with 0 icons doesn't make sense), but it should be fine, if it's zero nothing will be written to the buffer anyway.
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.
Sometimes if the spec (or whatever icon format this is working on), technically allows something it could probably be handled if it's technically possible, better to be robust imo than save a couple bytes. I've dealt with annoying .icns formats in the past which crashed a parser based on some weird assumption of practical formats and sizes.
Anywhoo should be same as master now
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.
Actually, i changed my mind. I think i'm going to revert it to my original implementation. It's safer in general, and safer for future contributors who may not have context or may not work at this allocation point. Sure there are some guards there now, but I don't like that the allocation has potential to be wrong and insufficient. Maybe it could also be exploited, etc.
There just shouldn't be a possible way to allocate unsufficient memory for the size of struct required, even with checks after allocation... At the minimum it should guarantee to always allocate sizeof(ICONDIR)
for safety regardless of any external multiplier (idCount).
a2c15c3
to
02be75f
Compare
I changed this commit to what is currently pushed to master... but I'm not sure what version is actually best. When i implemented, i didn't know what valid range of
|
02be75f
to
33c03a1
Compare
The CI error seems unrelated to this PR, likely Xcode got updated on GH Actions and it's now reporting this warning (which we treat as errors):
Will look into fixing this in a separate PR, then this will need a rebase to pass CI. |
Done, once rebased this should be good to go. |
This added an extra commit, we'd really prefer a rebase to keep the Git history clean. |
arg ya, didn't see the 2 commits there... Will rebase and resubmit monday, sry! |
c9d8b11
to
ae47e1d
Compare
Thanks! |
Cherry-picked for 3.5.2. |
Fixes #71697. Can probably be fixed on master as well.