Skip to content

Commit

Permalink
Bound-check before calls that raise OOB coord errors
Browse files Browse the repository at this point in the history
  • Loading branch information
LBPHacker committed Oct 9, 2023
1 parent fdbf58c commit 072cefe
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 2 deletions.
2 changes: 1 addition & 1 deletion tptmp/client/client.lua
Original file line number Diff line number Diff line change
Expand Up @@ -558,7 +558,7 @@ function client_i:handle_clearrect_67_()
self:member_prefix_()
local x, y = self:read_xy_12_()
local w, h = self:read_xy_12_()
sim.clearRect(x, y, w, h)
util.clear_rect(x, y, w, h)
end

function client_i:handle_canceldraw_68_()
Expand Down
22 changes: 22 additions & 0 deletions tptmp/client/util.lua
Original file line number Diff line number Diff line change
Expand Up @@ -527,6 +527,9 @@ local function rect_snap_coords(x1, y1, x2, y2)
end

local function create_parts_any(x, y, rx, ry, xtype, brush, member)
if not inside_rect(0, 0, sim.XRES, sim.YRES, x, y) then
return
end
if line_only[xtype] or no_create[xtype] then
return
end
Expand Down Expand Up @@ -571,6 +574,10 @@ local function create_parts_any(x, y, rx, ry, xtype, brush, member)
end

local function create_line_any(x1, y1, x2, y2, rx, ry, xtype, brush, member, cont)
if not inside_rect(0, 0, sim.XRES, sim.YRES, x1, y1) or
not inside_rect(0, 0, sim.XRES, sim.YRES, x2, y2) then
return
end
if no_create[xtype] or no_shape[xtype] or (jacobsmod and xtype == tpt.element("ball") and not member.kmod_s) then
return
end
Expand Down Expand Up @@ -670,6 +677,10 @@ local function create_line_any(x1, y1, x2, y2, rx, ry, xtype, brush, member, con
end

local function create_box_any(x1, y1, x2, y2, xtype, member)
if not inside_rect(0, 0, sim.XRES, sim.YRES, x1, y1) or
not inside_rect(0, 0, sim.XRES, sim.YRES, x2, y2) then
return
end
if line_only[xtype] or no_create[xtype] or no_shape[xtype] then
return
end
Expand Down Expand Up @@ -706,6 +717,9 @@ local function create_box_any(x1, y1, x2, y2, xtype, member)
end

local function flood_any(x, y, xtype, part_flood_hint, wall_flood_hint, member)
if not inside_rect(0, 0, sim.XRES, sim.YRES, x, y) then
return
end
if line_only[xtype] or no_create[xtype] or no_flood[xtype] then
return
end
Expand Down Expand Up @@ -737,6 +751,13 @@ local function flood_any(x, y, xtype, part_flood_hint, wall_flood_hint, member)
end
end

local function clear_rect(x, y, w, h)
if not inside_rect(0, 0, sim.XRES, sim.YRES, x + w, y + h) then
return
end
sim.clearRect(x, y, w, h)
end

local function corners_to_rect(x1, y1, x2, y2)
local xl = math.min(x1, x2)
local yl = math.min(y1, y2)
Expand Down Expand Up @@ -821,6 +842,7 @@ return {
create_line_any = create_line_any,
create_box_any = create_box_any,
flood_any = flood_any,
clear_rect = clear_rect,
from_tool = from_tool,
to_tool = to_tool,
create_override = create_override,
Expand Down
2 changes: 1 addition & 1 deletion tptmp/common/config.lua
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ return {
-- ***********************************************************************

-- * Protocol version, between 0 and 254. 255 is reserved for future use.
version = 28,
version = 29,

-- * Client-to-server message size limit, between 0 and 255, the latter
-- limit being imposted by the protocol.
Expand Down

0 comments on commit 072cefe

Please sign in to comment.