🐛 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;
|
index: TMulIndex;
|
||||||
begin
|
begin
|
||||||
radarcol := TFileStream.Create(ARadarCol, fmOpenRead);
|
radarcol := TFileStream.Create(ARadarCol, fmOpenRead);
|
||||||
SetLength(FRadarColors, radarcol.Size div SizeOf(Word));
|
try
|
||||||
radarcol.Read(FRadarColors[0], radarcol.Size);
|
SetLength(FRadarColors, radarcol.Size div SizeOf(Word));
|
||||||
radarcol.Free;
|
if Length(FRadarColors) > 0 then
|
||||||
|
radarcol.Read(FRadarColors[0], Length(FRadarColors) * SizeOf(Word));
|
||||||
|
finally
|
||||||
|
radarcol.Free;
|
||||||
|
end;
|
||||||
|
|
||||||
FWidth := AWidth;
|
FWidth := AWidth;
|
||||||
FHeight := AHeight;
|
FHeight := AHeight;
|
||||||
@@ -159,13 +163,14 @@ begin
|
|||||||
begin
|
begin
|
||||||
AMap.Read(mapCell, SizeOf(TMapCell));
|
AMap.Read(mapCell, SizeOf(TMapCell));
|
||||||
AMap.Seek(193, soFromCurrent);
|
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));
|
AStaIdx.Read(index, SizeOf(TMulIndex));
|
||||||
if (index.Position < $FFFFFFFF) and (index.Size > 0) then
|
if (index.Position < $FFFFFFFF) and (index.Size >= 7) then
|
||||||
begin
|
begin
|
||||||
AStatics.Position := index.Position;
|
AStatics.Position := index.Position;
|
||||||
SetLength(staticsItems, index.Size div 7);
|
SetLength(staticsItems, index.Size div 7);
|
||||||
AStatics.Read(staticsItems[0], index.Size);
|
AStatics.Read(staticsItems[0], Length(staticsItems) * SizeOf(TStaticItem));
|
||||||
highestZ := mapCell.Altitude;
|
highestZ := mapCell.Altitude;
|
||||||
for item := Low(staticsItems) to High(staticsItems) do
|
for item := Low(staticsItems) to High(staticsItems) do
|
||||||
begin
|
begin
|
||||||
@@ -173,7 +178,8 @@ begin
|
|||||||
(staticsItems[item].Z >= highestZ) then
|
(staticsItems[item].Z >= highestZ) then
|
||||||
begin
|
begin
|
||||||
highestZ := staticsItems[item].Z;
|
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;
|
end;
|
||||||
end;
|
end;
|
||||||
@@ -221,6 +227,7 @@ var
|
|||||||
packet: TPacket;
|
packet: TPacket;
|
||||||
begin
|
begin
|
||||||
block := AX * FHeight + AY;
|
block := AX * FHeight + AY;
|
||||||
|
if ATileID >= Length(FRadarColors) then Exit;
|
||||||
color := FRadarColors[ATileID];
|
color := FRadarColors[ATileID];
|
||||||
if FRadarMap[block] <> color then
|
if FRadarMap[block] <> color then
|
||||||
begin
|
begin
|
||||||
|
|||||||
Reference in New Issue
Block a user