From 208ad577777abe2d410e0ea85e53f8985e7eff45 Mon Sep 17 00:00:00 2001 From: Andreas Schneider Date: Sun, 15 Nov 2026 14:50:11 +0100 Subject: [PATCH] =?UTF-8?q?=F0=9F=90=9B=20Validate=20radar=20map=20file=20?= =?UTF-8?q?data?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Odd-sized radar color files, short static blocks, and tile IDs beyond the color table read or wrote past their arrays at startup. --- Server/URadarMap.pas | 21 ++++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-) diff --git a/Server/URadarMap.pas b/Server/URadarMap.pas index e772f05..513bfdd 100644 --- a/Server/URadarMap.pas +++ b/Server/URadarMap.pas @@ -142,9 +142,13 @@ var index: TMulIndex; begin radarcol := TFileStream.Create(ARadarCol, fmOpenRead); - SetLength(FRadarColors, radarcol.Size div SizeOf(Word)); - radarcol.Read(FRadarColors[0], radarcol.Size); - radarcol.Free; + try + SetLength(FRadarColors, radarcol.Size div SizeOf(Word)); + 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); - FRadarMap[i] := FRadarColors[mapCell.TileID]; + 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,7 +178,8 @@ begin (staticsItems[item].Z >= highestZ) then begin highestZ := staticsItems[item].Z; - FRadarMap[i] := FRadarColors[staticsItems[item].TileID + $4000]; + if staticsItems[item].TileID + $4000 < Length(FRadarColors) then + FRadarMap[i] := FRadarColors[staticsItems[item].TileID + $4000]; end; 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