OutpostUniverse / OP2MapImager

Render images of Outpost 2 maps using a Windows based console application.
https://wiki.outpost2.net/doku.php?id=outpost_2:helper_programs:map_imager
1 stars 0 forks source link

Move image dimension checks from PasteTile function to initialization of bmp #27

Closed Brett208 closed 5 years ago

Brett208 commented 5 years ago

Checks are run multiple times when forming an image for no reason. Check also doesn't handle possible wrap-around conditions if large enough values are multiplied. Thanks to Dan for doing the legwork identifying this problem.

Dimension checks should look something like:

if (scaleFactor > 0 && tileIndex > (std::numeric_limits<unsigned int>::max() - scaleFactor) / scaleFactor) {
}

https://stackoverflow.com/questions/1815367/catch-and-compute-overflow-during-multiplication-of-two-large-integers

DanRStevens commented 5 years ago

Do you remember the conversation where the above formula came from? I'd like to have a reference to the original discussion. I'm having trouble tracking down where we came up with:

if (scaleFactor > 0 && tileIndex > (std::numeric_limits<unsigned int>::max() - scaleFactor) / scaleFactor)

I vaguely remember it being something about a check done while pasting tiles, rather than when the tilesets were scaled.

Brett208 commented 5 years ago

Check this page for the comment in the code section. If it doesn't display for you, I'll paste in here:

https://github.com/OutpostUniverse/OP2MapImager/commit/ca053ffcc801da5e1e40ac95af88d37e65629e7f#commitcomment-31363703