🚨 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:
2026-11-15 22:06:51 +01:00
parent 1335e3f40e
commit fa288fddf8
+31 -26
View File
@@ -1198,42 +1198,47 @@ var
begin begin
AssignFile(noDrawFile, AFileName); AssignFile(noDrawFile, AFileName);
Reset(noDrawFile); Reset(noDrawFile);
while not EOF(noDrawFile) do try
begin while not EOF(noDrawFile) do
ReadLn(noDrawFile, line);
if (Length(line) > 0) and (line[1] in ['S', 'T']) then
begin begin
splitPos := Pos('-', line); ReadLn(noDrawFile, line);
if splitPos > 1 then if (Length(line) > 0) and (line[1] in ['S', 'T']) then
begin begin
ids1 := Copy(line, 2, splitPos - 2); splitPos := Pos('-', line);
ids2 := Copy(line, splitPos + 1, Length(line)); if splitPos > 1 then
if TryStrToInt(ids1, id1) and TryStrToInt(ids2, id2) then
begin 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 begin
Inc(id1, $4000); if line[1] = 'S' then
Inc(id2, $4000); begin
end; Inc(id1, $4000);
Inc(id2, $4000);
end;
for i := id1 to id2 do if id1 < 0 then
if i < FDrawMap.Size then id1 := 0;
FDrawMap[i] := False; for i := id1 to id2 do
end; if i < FDrawMap.Size then
end else FDrawMap[i] := False;
begin end;
ids1 := Copy(line, 2, Length(line)); end else
if TryStrToInt(ids1, id1) then
begin begin
if line[1] = 'S' then ids1 := Copy(line, 2, Length(line));
Inc(id1, $4000); if TryStrToInt(ids1, id1) then
if id1 < FDrawMap.Size then begin
FDrawMap[id1] := False; if line[1] = 'S' then
Inc(id1, $4000);
if (id1 >= 0) and (id1 < FDrawMap.Size) then
FDrawMap[id1] := False;
end;
end; end;
end; end;
end; end;
finally
CloseFile(noDrawFile);
end; end;
CloseFile(noDrawFile);
end; end;
procedure TLandscape.MoveStatic(AStatic: TStaticItem; AX, AY: Word); procedure TLandscape.MoveStatic(AStatic: TStaticItem; AX, AY: Word);