Skip to content
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

Fix out of bounds access into empty image data #46247

Closed
wants to merge 1 commit into from
Closed

Fix out of bounds access into empty image data #46247

wants to merge 1 commit into from

Conversation

nmrkr
Copy link
Contributor

@nmrkr nmrkr commented Feb 20, 2021

Fixes #46189.

This issue only affects X11.

Cherry-picking this does not seem possible due to restructuring. I have submitted #46249 to apply this fix to the 3.2 branch.

@nmrkr nmrkr requested a review from a team as a code owner February 20, 2021 10:30
@nmrkr nmrkr marked this pull request as draft February 20, 2021 10:32
@nmrkr nmrkr marked this pull request as ready for review February 20, 2021 13:43
v |= pr[3] << 24 | pr[0] << 16 | pr[1] << 8 | pr[2];
*wr++ = v;
pr += 4;
if (w > 0 && h > 0) {
Copy link
Member

Choose a reason for hiding this comment

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

I think the check should be earlier, likely together with if (p_icon.is_valid()). There's no reason to do all the processing above for an invalid icon.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This was also my first idea. But then setting an empty Ref would be semantically equivalent to setting a valid but empty image. I am not familiar enough with X11 to say wether or not calling XDeleteProperty on net_wm_icon is actually the same as calling XChangeProperty with an empty image. I see no difference in behaviour on my particular setup, but I didn't want to remove the distinction between the two code paths without being sure.

This function is unlikely to be called at a high enough frequency for the performance difference to matter, but I'm also not invested in this particular solution and will gladly change it to an earlier exit. Your call :)

Copy link
Contributor

Choose a reason for hiding this comment

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

It should be fine to call XDeleteProperty for en empty image.

Actually, in order to make it consistent with other platforms, an invalid image could be handled with ERR_FAIL_COND(!p_icon.is_valid()); so it would just raise an error, and the proper way to set no icon would be to use an empty image.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Consistency across all platforms sounds like a very good goal. Should this then be moved into a separate issue?

In any case, here's the situation as it currently is in master:

X11 Win UWP OSX JS
Empty Ref Remove Icon ERR_FAIL_COND Silently does nothing Crash ERR_FAIL_COND
Empty Image Crash Use Empty Image as Icon Silently does nothing ERR_FAIL_COND Use Empty Image as Icon

Looking at the other platforms actually revealed another bug. OSX dereferences the Ref unchecked and crashes on set_icon(null).

I guess there should be an executive decision on what The Right Thing™ to do is for each case.

Copy link
Contributor

Choose a reason for hiding this comment

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

I think it should be safe to say the current behavior on Windows is the way to go accross platforms, but let's see if there's a consensus in @godotengine/_platforms.

The current PR could address it completely on X11 by removing the icon on empty image and error on empty ref. OSX needs to be addresses in a separate PR.

Copy link
Member

Choose a reason for hiding this comment

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

Yeah I think the Windows/JS behavior is good and should be used for all platforms.

@akien-mga akien-mga added this to the 4.0 milestone Feb 21, 2021
@akien-mga akien-mga requested a review from a team February 21, 2021 11:51
@akien-mga akien-mga added the cherrypick:3.x Considered for cherry-picking into a future 3.x release label Jul 2, 2022
@YuriSizov YuriSizov modified the milestones: 4.0, 4.1 Feb 12, 2023
@YuriSizov
Copy link
Contributor

This PR needs a rebase and to address the discussion above.

@akien-mga
Copy link
Member

Superseded by #78437.

@akien-mga akien-mga closed this Jun 19, 2023
@akien-mga akien-mga added archived and removed cherrypick:3.x Considered for cherry-picking into a future 3.x release labels Jun 19, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Executing OS.set_icon(Image.new()) crashes Godot
5 participants