🚨 Harden the nodraw map loader
A parse error leaked the file handle and negative IDs from a malformed file indexed the draw bitmap out of bounds.
This commit is contained in:
@@ -1198,6 +1198,7 @@ var
|
|||||||
begin
|
begin
|
||||||
AssignFile(noDrawFile, AFileName);
|
AssignFile(noDrawFile, AFileName);
|
||||||
Reset(noDrawFile);
|
Reset(noDrawFile);
|
||||||
|
try
|
||||||
while not EOF(noDrawFile) do
|
while not EOF(noDrawFile) do
|
||||||
begin
|
begin
|
||||||
ReadLn(noDrawFile, line);
|
ReadLn(noDrawFile, line);
|
||||||
@@ -1216,6 +1217,8 @@ begin
|
|||||||
Inc(id2, $4000);
|
Inc(id2, $4000);
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
if id1 < 0 then
|
||||||
|
id1 := 0;
|
||||||
for i := id1 to id2 do
|
for i := id1 to id2 do
|
||||||
if i < FDrawMap.Size then
|
if i < FDrawMap.Size then
|
||||||
FDrawMap[i] := False;
|
FDrawMap[i] := False;
|
||||||
@@ -1227,13 +1230,15 @@ begin
|
|||||||
begin
|
begin
|
||||||
if line[1] = 'S' then
|
if line[1] = 'S' then
|
||||||
Inc(id1, $4000);
|
Inc(id1, $4000);
|
||||||
if id1 < FDrawMap.Size then
|
if (id1 >= 0) and (id1 < FDrawMap.Size) then
|
||||||
FDrawMap[id1] := False;
|
FDrawMap[id1] := False;
|
||||||
end;
|
end;
|
||||||
end;
|
end;
|
||||||
end;
|
end;
|
||||||
end;
|
end;
|
||||||
|
finally
|
||||||
CloseFile(noDrawFile);
|
CloseFile(noDrawFile);
|
||||||
|
end;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
procedure TLandscape.MoveStatic(AStatic: TStaticItem; AX, AY: Word);
|
procedure TLandscape.MoveStatic(AStatic: TStaticItem; AX, AY: Word);
|
||||||
|
|||||||
Reference in New Issue
Block a user