Fix Amiga2 palette bounds handling#120
Merged
Merged
Conversation
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.
Motivation
.PALbuffers and write past the fixed 256-entrymPalettearray, enabling local asset-triggered memory corruption..PALas 3-byte triplets while callers passed byte counts to the loader and some calls start at high palette indices (e.g.0xE0).Description
cGraphics_Amiga2::GetPalette()to only consume complete 3-byte RGB triplets by iterating withfor (; a0 + 2 < a0End; a0 += 3)and usinga0[0],a0[1],a0[2]for conversion to avoid out-of-bounds reads. (file:Source/Amiga/Graphics_Amiga2.cpp)Source/Amiga/Graphics_Amiga2.cpp)sImage::LoadPalette_Amiga()to the validmPaletterange by early-returning ifpStartColorID >= 256and usingstd::min(pCount, 256 - pStartColorID)for the loop count to prevent out-of-bounds writes. (file:Source/Graphics.hpp)Testing
rgandsedto verify modifications, and the checks succeeded.git diff -- Source/Amiga/Graphics_Amiga2.cpp Source/Graphics.hppand it showed the intended changes.git add/git commitand created the PR metadata viamake_pr, and all commands completed successfully.Codex Task