From 0f8e385d23f419e2faed7465d871c0260eda1a1c Mon Sep 17 00:00:00 2001 From: Walter Agazzi Date: Thu, 24 Aug 2023 19:02:21 +0200 Subject: [PATCH 1/3] Engine: Fix possible index out of bounds in SetBlender --- Engine/gfx/gfx_util.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Engine/gfx/gfx_util.cpp b/Engine/gfx/gfx_util.cpp index 1ce158674ee..1ce75fec9f6 100644 --- a/Engine/gfx/gfx_util.cpp +++ b/Engine/gfx/gfx_util.cpp @@ -66,7 +66,7 @@ static const BlendModeSetter BlendModeSets[kNumBlendModes] = bool SetBlender(BlendMode blend_mode, bool dst_has_alpha, bool src_has_alpha, int blend_alpha) { - if (blend_mode < 0 || blend_mode > kNumBlendModes) + if (blend_mode < 0 || blend_mode >= kNumBlendModes) return false; const BlendModeSetter &set = BlendModeSets[blend_mode]; PfnBlenderCb blender; @@ -151,7 +151,7 @@ void DrawSpriteWithTransparency(Bitmap *ds, Bitmap *sprite, int x, int y, int al } sprite = &hctemp; } - + if ((alpha < 0xFF) && (surface_depth > 8) && (sprite_depth > 8)) { set_trans_blender(0, 0, 0, alpha); From 3e25fc6a550b471f472af80ac87966f8998d7fc7 Mon Sep 17 00:00:00 2001 From: Walter Agazzi Date: Thu, 24 Aug 2023 20:06:56 +0200 Subject: [PATCH 2/3] AGSPalRender: Fix possible index out of bounds --- Plugins/agspalrender/raycast.cpp | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/Plugins/agspalrender/raycast.cpp b/Plugins/agspalrender/raycast.cpp index dcffe10262d..68a65deec70 100755 --- a/Plugins/agspalrender/raycast.cpp +++ b/Plugins/agspalrender/raycast.cpp @@ -96,8 +96,8 @@ unsigned char selectedColor; void Ray_SelectTile (int x,int y, unsigned char color) { - if (x < 0 || x > mapWidth) selectedX = -1; - else if (y < 0 || y > mapWidth) selectedY = -1; + if (x < 0 || x >= mapWidth) selectedX = -1; + else if (y < 0 || y >= mapWidth) selectedY = -1; else { selectedX = x; @@ -108,8 +108,8 @@ void Ray_SelectTile (int x,int y, unsigned char color) int Ray_HasSeenTile (int x,int y) { - if (x < 0 || x > mapWidth) return -1; - else if (y < 0 || y > mapWidth) return -1; + if (x < 0 || x >= mapWidth) return -1; + else if (y < 0 || y >= mapWidth) return -1; return seenMap [x][y]; } @@ -661,33 +661,33 @@ void MakeTextures (int slot) void Ray_SetFloorAt (int x,int y,int tex) { - if (x < 0 || x > mapWidth || y < 0 || y > mapHeight || tex > 511) return; + if (x < 0 || x >= mapWidth || y < 0 || y >= mapHeight || tex > 511) return; else floorMap[x][y] = tex; } void Ray_SetCeilingAt (int x,int y,int tex) { - if (x < 0 || x > mapWidth || y < 0 || y > mapHeight || tex > 511) return; + if (x < 0 || x >= mapWidth || y < 0 || y >= mapHeight || tex > 511) return; else ceilingMap[x][y] = tex; } int Ray_GetCeilingAt (int x,int y) { - if (x < 0 || x > mapWidth || y < 0 || y > mapHeight) return -1; + if (x < 0 || x >= mapWidth || y < 0 || y >= mapHeight) return -1; else return ceilingMap [x][y]; } int Ray_GetFloorAt (int x,int y) { - if (x < 0 || x > mapWidth || y < 0 || y > mapHeight) return -1; + if (x < 0 || x >= mapWidth || y < 0 || y >= mapHeight) return -1; else return floorMap [x][y]; } int Ray_GetLightingAt (int x,int y) { - if (x < 0 || x > mapWidth || y < 0 || y > mapHeight) return -1; + if (x < 0 || x >= mapWidth || y < 0 || y >= mapHeight) return -1; else { int lighting=0; @@ -702,7 +702,7 @@ int Ray_GetLightingAt (int x,int y) void Ray_SetLightingAt (int x,int y,unsigned char lighting) { - if (x < 0 || x > mapWidth || y < 0 || y > mapHeight) return; + if (x < 0 || x >= mapWidth || y < 0 || y >= mapHeight) return; else { lightMap [x][y] = lighting; From 48642c23b7dd1624935a4ed307ecbc4b6f309fe3 Mon Sep 17 00:00:00 2001 From: Walter Agazzi Date: Thu, 24 Aug 2023 20:16:42 +0200 Subject: [PATCH 3/3] AGSPalRender: Properly use mapWidth/mapHeight --- Plugins/agspalrender/raycast.cpp | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/Plugins/agspalrender/raycast.cpp b/Plugins/agspalrender/raycast.cpp index 68a65deec70..fb8aafb295b 100755 --- a/Plugins/agspalrender/raycast.cpp +++ b/Plugins/agspalrender/raycast.cpp @@ -97,7 +97,7 @@ unsigned char selectedColor; void Ray_SelectTile (int x,int y, unsigned char color) { if (x < 0 || x >= mapWidth) selectedX = -1; - else if (y < 0 || y >= mapWidth) selectedY = -1; + else if (y < 0 || y >= mapHeight) selectedY = -1; else { selectedX = x; @@ -109,7 +109,7 @@ void Ray_SelectTile (int x,int y, unsigned char color) int Ray_HasSeenTile (int x,int y) { if (x < 0 || x >= mapWidth) return -1; - else if (y < 0 || y >= mapWidth) return -1; + else if (y < 0 || y >= mapHeight) return -1; return seenMap [x][y]; } @@ -127,8 +127,8 @@ void Ray_DrawTile (int spr,int tile) { BITMAP *sprite = engine->GetSpriteGraphic (spr); unsigned char** sprarray = engine->GetRawBitmapSurface (sprite); - for (int y=0;y<64;++y) - for (int x=0;x<64;++x) + for (int y=0;yReleaseBitmapSurface (sprite); } @@ -137,8 +137,8 @@ void Ray_DrawOntoTile (int spr,int tile) { BITMAP *sprite = engine->GetSpriteGraphic (spr); unsigned char** sprarray = engine->GetRawBitmapSurface (sprite); - for (int y=0;y<64;++y) - for (int x=0;x<64;++x) + for (int y=0;yReleaseBitmapSurface (sprite); }