🐛 Validate radar map file data

Odd-sized radar color files, short static blocks, and tile IDs
beyond the color table read or wrote past their arrays at startup.
This commit is contained in:
2026-11-15 22:08:32 +01:00
parent 6df8df9a9b
commit 208ad57777
+10 -3
View File
@@ -142,9 +142,13 @@ var
index: TMulIndex;
begin
radarcol := TFileStream.Create(ARadarCol, fmOpenRead);
try
SetLength(FRadarColors, radarcol.Size div SizeOf(Word));
radarcol.Read(FRadarColors[0], radarcol.Size);
if Length(FRadarColors) > 0 then
radarcol.Read(FRadarColors[0], Length(FRadarColors) * SizeOf(Word));
finally
radarcol.Free;
end;
FWidth := AWidth;
FHeight := AHeight;
@@ -159,13 +163,14 @@ begin
begin
AMap.Read(mapCell, SizeOf(TMapCell));
AMap.Seek(193, soFromCurrent);
if mapCell.TileID < Length(FRadarColors) then
FRadarMap[i] := FRadarColors[mapCell.TileID];
AStaIdx.Read(index, SizeOf(TMulIndex));
if (index.Position < $FFFFFFFF) and (index.Size > 0) then
if (index.Position < $FFFFFFFF) and (index.Size >= 7) then
begin
AStatics.Position := index.Position;
SetLength(staticsItems, index.Size div 7);
AStatics.Read(staticsItems[0], index.Size);
AStatics.Read(staticsItems[0], Length(staticsItems) * SizeOf(TStaticItem));
highestZ := mapCell.Altitude;
for item := Low(staticsItems) to High(staticsItems) do
begin
@@ -173,6 +178,7 @@ begin
(staticsItems[item].Z >= highestZ) then
begin
highestZ := staticsItems[item].Z;
if staticsItems[item].TileID + $4000 < Length(FRadarColors) then
FRadarMap[i] := FRadarColors[staticsItems[item].TileID + $4000];
end;
end;
@@ -221,6 +227,7 @@ var
packet: TPacket;
begin
block := AX * FHeight + AY;
if ATileID >= Length(FRadarColors) then Exit;
color := FRadarColors[ATileID];
if FRadarMap[block] <> color then
begin