🐛 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:
+14
-7
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user