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 int overflow when using fillr in negative y-coordinates #2082

Merged
merged 3 commits into from
Sep 19, 2023

Conversation

dordsor21
Copy link
Contributor

@dordsor21 dordsor21 commented Apr 20, 2022

 - Also actually check the depth arg against the radius limit
@dordsor21
Copy link
Contributor Author

dordsor21 commented Apr 20, 2022

If checking the depth size against max allowed radius should be done for fillr then it should also be done for fill, otherwise, the checkmaxradius in fillr should be removed, and the old default behaviour of "infinite depth" be re-added if no depth parameter is given

@octylFractal
Copy link
Member

I don't understand how this fixes a negative y-coord issue. It seems like you only changed the value used if depth isn't passed, but I can't connect that to fixing y-coord issues if you passed e.g. 1 instead.

@dordsor21
Copy link
Contributor Author

dordsor21 commented Apr 20, 2022

The depth is subtracted from the height of the player in the fillXZ method in editsession https://github.com/EngineHub/WorldEdit/blob/master/worldedit-core/src/main/java/com/sk89q/worldedit/EditSession.java#L1007. Using Integer.MAX_VALUE causes an overflow with negative values, so changing the default depth fixes it. It makes sense to also ensure that the depth does not exceed the max radius set, as it is effectively a radius in itself

@octylFractal
Copy link
Member

Sounds like something that should be fixed in the method itself, because it's API -- people can still call it with MAX_VALUE and get bad behavior. Or pass MAX_VALUE as their depth in the command. This isn't a true fix if the method itself isn't protected against the overflow.

@dordsor21
Copy link
Contributor Author

dordsor21 commented Apr 20, 2022

Separate to that (which would just be a bound to Integer.MIN_VALUE I suppose), should the depth be able to be larger than the max radius configured?

There are also other places overflows can occur, e.g. https://github.com/EngineHub/WorldEdit/blob/master/worldedit-core/src/main/java/com/sk89q/worldedit/EditSession.java#L1682

@@ -101,6 +101,7 @@ public int fill(Actor actor, LocalSession session, EditSession editSession,
radius = Math.max(1, radius);
we.checkMaxRadius(radius);
depth = Math.max(1, depth);
we.checkMaxRadius(depth);
Copy link
Member

Choose a reason for hiding this comment

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

So from looking at this, it doesn't actually appear that any of the changes in UtilityCommands.java are actually required here. And these do modify the behaviour of the commands.

Can this PR please be modified to only include the changes within EditSession.java?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeah, will do

Copy link
Contributor Author

Choose a reason for hiding this comment

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

All done!

@me4502 me4502 merged commit 3627002 into EngineHub:version/7.2.x Sep 19, 2023
4 checks passed
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