Small safety fixes: RNC header bounds, hand-rule guards, multi-monitor frontend#4986
Closed
matthewdeaves wants to merge 3 commits into
Closed
Small safety fixes: RNC header bounds, hand-rule guards, multi-monitor frontend#4986matthewdeaves wants to merge 3 commits into
matthewdeaves wants to merge 3 commits into
Conversation
UnpackM1() memcpy'd sizeof(rnc_header) bytes out of the caller's buffer before checking its size, an out-of-bounds read when the buffer is smaller than the RNC header. Return 0 (the existing "not compressed" result) if the buffer can't even hold a header. Adapted from cerwym/keeperfx@643f618e (Peter Lockett). Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
thing_pickup_is_blocked_by_hand_rule() indexed dungeon->hand_rules[model][i] without validating either: an invalid dungeon (e.g. neutral/unowned player) dereferenced a bad pointer, and a creature model outside [0, CREATURE_TYPES_MAX) read out of bounds of the hand_rules array. Guard both and log the offending thing. Adapted from cerwym/keeperfx@16cdd064 (Peter Lockett). Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
LbGetCurrentDisplayIndex() defaulted to display 0 when no game window exists yet (splash/legal/frontend setup), so on a multi-monitor setup the splash and frontend could size for the wrong monitor. When there's no window, query the global cursor position and pick the display containing it — this is also the monitor a Wayland compositor will open the window on. Helps macOS/Linux/Windows multi-monitor alike. Adapted from DoubyCz/keeperfx@3b5460a7b3. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Contributor
|
I guess I should be flattered, but please adjust the commit messages to have the original author as a Co-Author, much like Claude is appending; So, instruct your tool to add 'Co authored by cerwym (1760289+cerwym@users.noreply.github.com); This will correctly list me and other authors in the blame for git. |
Contributor
|
Number 3 is completely wrong. Keep that LLM poop out of here. The context of other forks doesn't matter as long as it isn't part of the master. We set the correct monitor trough the config variable This PR breaks that functionality and introduces the cursor placement position which nobody wants when starting up a game. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Three small, independent fixes — each in its own commit.
1.
dernc: bounds-checkUnpackM1It copied the 18-byte RNC header out of the buffer before checking the buffer was that big, so a file smaller than the header caused an out-of-bounds read. Now it returns early (as "not compressed") when the buffer is too small.
2.
power_hand: guard invalid dungeon and out-of-range modelthing_pickup_is_blocked_by_hand_rule()indexeddungeon->hand_rules[model]without checking the dungeon was valid or thatmodelwas in[0, CREATURE_TYPES_MAX). An invalid dungeon (e.g. an unowned player) or a bad model dereferenced a bad pointer / read out of bounds. Both are now guarded, with a log line for the offending thing.3.
video: pick the display under the cursor for the pre-window frontendBefore a game window exists (splash/frontend),
LbGetCurrentDisplayIndex()always returned display 0, so on multi-monitor setups the splash could size for the wrong screen. It now picks the display containing the mouse cursor, falling back to the old default. (Also the monitor a Wayland compositor opens the window on.)The first two are adapted from @cerwym's fork, the third from @DoubyCz's — credited in the commit messages. I came across them while working on a native macOS build and they looked worth sending on their own.
Disclosure: reviewed and prepared with the help of Claude Code.