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

(#2509) Handling integer overflows for dimensions for XWaylandSurface #3049

Closed
wants to merge 2 commits into from

Conversation

mattkae
Copy link
Contributor

@mattkae mattkae commented Sep 21, 2023

#2509

You can find some more info on the solution to this one in the ticket itself ☝️

How to test

  • Run miral-app or something
  • Open up mattermost
  • Click the fullscreen button or resize it using the edges
  • Note that this now works!

Solution

  • I am going to assume that the width and height are never naturally negative. Hence, if we overflow during the multiplication, we can expect the int to go negative.
  • This might just be an unsafe multiplication all-around, especially if we have a negative scale (e.g. a scale of 0.25 would result in an inv_scale of 8)

Screen recording

Screencast.from.09-21-2023.05.02.28.PM.webm

@mattkae mattkae marked this pull request as ready for review September 21, 2023 21:03
@codecov
Copy link

codecov bot commented Sep 21, 2023

Codecov Report

Merging #3049 (eac793b) into main (da0c8fa) will increase coverage by 0.00%.
Report is 2 commits behind head on main.
The diff coverage is n/a.

@@           Coverage Diff           @@
##             main    #3049   +/-   ##
=======================================
  Coverage   77.70%   77.70%           
=======================================
  Files        1056     1056           
  Lines       73403    73403           
=======================================
+ Hits        57039    57041    +2     
+ Misses      16364    16362    -2     
Files Changed Coverage Δ
src/server/frontend_xwayland/xwayland_surface.cpp 0.00% <ø> (ø)

... and 5 files with indirect coverage changes

📣 We’re building smart automated test selection to slash your CI/CD build times. Learn more

Copy link
Contributor

@RAOF RAOF left a comment

Choose a reason for hiding this comment

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

Hm. I think this might be better handled in the converting Value constructors? (geometry/dimensions.h lines 72 and 78)

Rather than just YOLOing static_cast<> there, do a saturating cast? (ie: check value against std::numeric_limits<T> and return ::max/::min as appropriate).

There's never a case where we want UB there (which is the current situation) and I don't think there's ever a case where we'd want anything other than saturation?

@AlanGriffiths
Copy link
Contributor

Thanks for tracking this down, but I don't like this solution either. And I'm not sure the converting constructor is the place either. See also #3050

@mattkae mattkae closed this Sep 22, 2023
@mattkae mattkae deleted the bugfix/2509 branch September 22, 2023 15:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants