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

Possible UB in pokemon_storage_system.c #2106

Open
luckytyphlosion opened this issue Feb 27, 2025 · 2 comments
Open

Possible UB in pokemon_storage_system.c #2106

luckytyphlosion opened this issue Feb 27, 2025 · 2 comments

Comments

@luckytyphlosion
Copy link
Member

https://github.com/pret/pokeemerald/blob/9bf7a77/src/pokemon_storage_system.c#L560
static u32 sItemIconGfxBuffer[98]; think this definition causes UB, the sprite sheet size is 0x200 but this only allocates 0x188 bytes

https://github.com/pret/pokeemerald/blob/9bf7a77/src/pokemon_storage_system.c#L8735-L8737

        spriteSheet.data = sItemIconGfxBuffer;
        spriteSheet.size = 0x200;
        spriteTemplate = sSpriteTemplate_ItemIcon;

Noticed this when I tried to move this buffer to alloc'd space

@luckytyphlosion
Copy link
Member Author

Edit: the size was not the issue, it is because the game tries to decompress from sItemIconGfxBuffer, even though it's in memory. this only works out because sItemIconGfxBuffer is never written to.

@luckytyphlosion
Copy link
Member Author

there is another issue
at LoadSpriteSheet (from LoadCompressedSpriteSheet), the game will copy over the sheet data to vram
the problem is that this sheet data is completely uninitalized
https://github.com/pret/pokeemerald/blob/9bf7a77/src/decompress.c#L27
writes gDecompressionBuffer to data but that was never written to
https://github.com/pret/pokeemerald/blob/9bf7a77/src/sprite.c#L1499
then copies that to vram
it is never an issue because it is only done for the purpose of allocating sprite tiles for the held items in the storage

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

No branches or pull requests

1 participant