Bound the multiplayer map preview against the block it arrives in - #144
Bound the multiplayer map preview against the block it arrives in#144gunnarbeutner wants to merge 1 commit into
Conversation
|
Development builds of 7cdf613: The links work without a GitHub account. Artifacts expire after 90 days, and this comment follows the latest successful build. |
|
Receive_Random_Map_Preview should be refactored to use a bool, say valid to always reach the one and only cleanup instead of copying the cleanups |
|
The print terminology is very weird.. |
daa3f2c to
7cdf613
Compare
|
I've updated the log messages, replaced the buffers with |
Invalid preview data from a multiplayer host could cause out-of-bounds reads, overflow the allocation size calculation, or leave partially uninitialised data to be parsed.
This PR validates the received data before creating a preview:
Check the downloaded block and decompression result.
Receive_Random_Map_Previewnow checks that the file contains its length field and bounds the expanded size.BufferStrawreceives the number of bytes remaining after that field, fixing a four-byte overread.The caller allocates exactly the requested size, removing the unchecked
2 * preview_sizecalculation, and checks that decompression returned the full block before parsing it.Check the image fits within the block.
MapPreviewClass::Create_Preview_Surfacenow takes the block length and returns whether it created a surface. It validates the dimensions and colour count before reading the image, using 64-bit arithmetic for theoffset + width * heightcheck. Palette indices are bounded by the colour count.Keep the limits alongside the format definition.
Both limits live in
preview.hbeside the header they describe and are well above anythingCreate_Paletted_Previewproduces.