🚨 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:
+31
-26
@@ -1198,42 +1198,47 @@ var
|
||||
begin
|
||||
AssignFile(noDrawFile, AFileName);
|
||||
Reset(noDrawFile);
|
||||
while not EOF(noDrawFile) do
|
||||
begin
|
||||
ReadLn(noDrawFile, line);
|
||||
if (Length(line) > 0) and (line[1] in ['S', 'T']) then
|
||||
try
|
||||
while not EOF(noDrawFile) do
|
||||
begin
|
||||
splitPos := Pos('-', line);
|
||||
if splitPos > 1 then
|
||||
ReadLn(noDrawFile, line);
|
||||
if (Length(line) > 0) and (line[1] in ['S', 'T']) then
|
||||
begin
|
||||
ids1 := Copy(line, 2, splitPos - 2);
|
||||
ids2 := Copy(line, splitPos + 1, Length(line));
|
||||
if TryStrToInt(ids1, id1) and TryStrToInt(ids2, id2) then
|
||||
splitPos := Pos('-', line);
|
||||
if splitPos > 1 then
|
||||
begin
|
||||
if line[1] = 'S' then
|
||||
ids1 := Copy(line, 2, splitPos - 2);
|
||||
ids2 := Copy(line, splitPos + 1, Length(line));
|
||||
if TryStrToInt(ids1, id1) and TryStrToInt(ids2, id2) then
|
||||
begin
|
||||
Inc(id1, $4000);
|
||||
Inc(id2, $4000);
|
||||
end;
|
||||
if line[1] = 'S' then
|
||||
begin
|
||||
Inc(id1, $4000);
|
||||
Inc(id2, $4000);
|
||||
end;
|
||||
|
||||
for i := id1 to id2 do
|
||||
if i < FDrawMap.Size then
|
||||
FDrawMap[i] := False;
|
||||
end;
|
||||
end else
|
||||
begin
|
||||
ids1 := Copy(line, 2, Length(line));
|
||||
if TryStrToInt(ids1, id1) then
|
||||
if id1 < 0 then
|
||||
id1 := 0;
|
||||
for i := id1 to id2 do
|
||||
if i < FDrawMap.Size then
|
||||
FDrawMap[i] := False;
|
||||
end;
|
||||
end else
|
||||
begin
|
||||
if line[1] = 'S' then
|
||||
Inc(id1, $4000);
|
||||
if id1 < FDrawMap.Size then
|
||||
FDrawMap[id1] := False;
|
||||
ids1 := Copy(line, 2, Length(line));
|
||||
if TryStrToInt(ids1, id1) then
|
||||
begin
|
||||
if line[1] = 'S' then
|
||||
Inc(id1, $4000);
|
||||
if (id1 >= 0) and (id1 < FDrawMap.Size) then
|
||||
FDrawMap[id1] := False;
|
||||
end;
|
||||
end;
|
||||
end;
|
||||
end;
|
||||
finally
|
||||
CloseFile(noDrawFile);
|
||||
end;
|
||||
CloseFile(noDrawFile);
|
||||
end;
|
||||
|
||||
procedure TLandscape.MoveStatic(AStatic: TStaticItem; AX, AY: Word);
|
||||
|
||||
Reference in New Issue
Block a user