Files
UnrealEngineUWP/Engine/Source/Runtime/AugmentedReality/Private/ARSharedWorldPlayerController.cpp
steve smith 0fbdc18665 Fix potential buffer overflow condition.
#rb
#jira UE-85997
#preflight trivial

#ROBOMERGE-AUTHOR: steve.smith
#ROBOMERGE-SOURCE: CL 18626106 in //UE5/Release-5.0/... via CL 18626109 via CL 18626114
#ROBOMERGE-BOT: UE5 (Release-Engine-Test -> Main) (v899-18417669)

[CL 18626116 by steve smith in ue5-main branch]
2022-01-14 20:14:30 -05:00

91 lines
3.1 KiB
C++

// Copyright Epic Games, Inc. All Rights Reserved.
#include "ARSharedWorldPlayerController.h"
#include "ARSharedWorldGameState.h"
#include "Engine/World.h"
#include "AugmentedRealityModule.h"
AARSharedWorldPlayerController::AARSharedWorldPlayerController(const FObjectInitializer& ObjectInitializer)
: Super(ObjectInitializer)
, bIsReadyToReceive(false)
{
}
AARSharedWorldGameState* AARSharedWorldPlayerController::GetGameState()
{
UWorld* World = GetWorld();
AARSharedWorldGameState* GameState = World != nullptr ? CastChecked<AARSharedWorldGameState>(World->GetGameState()) : nullptr;
return GameState;
}
bool AARSharedWorldPlayerController::IsGameStateReady()
{
UWorld* World = GetWorld();
AARSharedWorldGameState* GameState = World != nullptr ? Cast<AARSharedWorldGameState>(World->GetGameState()) : nullptr;
return GameState != nullptr;
}
void AARSharedWorldPlayerController::Tick(float DeltaSeconds)
{
Super::Tick(DeltaSeconds);
// If we are the client, check that our game state has replicated over
if (!HasAuthority() && !bIsReadyToReceive && IsGameStateReady())
{
bIsReadyToReceive = true;
ServerMarkReadyForReceiving();
UE_LOG(LogAR, Verbose, TEXT("Notifying server ready to receive via ServerMarkReadyForReceiving()"));
}
}
bool AARSharedWorldPlayerController::ServerMarkReadyForReceiving_Validate()
{
return true;
}
void AARSharedWorldPlayerController::ServerMarkReadyForReceiving_Implementation()
{
bIsReadyToReceive = true;
UE_LOG(LogAR, Verbose, TEXT("Client is ready to receive"));
}
bool AARSharedWorldPlayerController::ClientInitSharedWorld_Validate(int32 PreviewImageSize, int32 ARWorldDataSize)
{
return PreviewImageSize >= 0 && PreviewImageSize <= (8 * 1024 * 1024) && ARWorldDataSize >= 0 && ARWorldDataSize <= (128 * 1024 * 1024);
}
void AARSharedWorldPlayerController::ClientInitSharedWorld_Implementation(int32 PreviewImageSize, int32 ARWorldDataSize)
{
UE_LOG(LogAR, Verbose, TEXT("Client received ClientInitSharedWorld(%d, %d)"), PreviewImageSize, ARWorldDataSize);
GetGameState()->InitSharedWorld(PreviewImageSize, ARWorldDataSize);
}
bool AARSharedWorldPlayerController::ClientUpdatePreviewImageData_Validate(int32 Offset, const TArray<uint8>& Buffer)
{
// Validate offset, and also check for signed integer overflow case.
return Offset >= 0 && (Offset + Buffer.Num()) >= 0;
}
void AARSharedWorldPlayerController::ClientUpdatePreviewImageData_Implementation(int32 Offset, const TArray<uint8>& Buffer)
{
UE_LOG(LogAR, Verbose, TEXT("Client received ClientUpdatePreviewImageData(%d, %d)"), Offset, Buffer.Num());
GetGameState()->UpdatePreviewImageData(Offset, Buffer.GetData(), Buffer.Num());
}
bool AARSharedWorldPlayerController::ClientUpdateARWorldData_Validate(int32 Offset, const TArray<uint8>& Buffer)
{
// Validate offset, and also check for signed integer overflow case.
return Offset >= 0 && (Offset + Buffer.Num()) >= 0;
}
void AARSharedWorldPlayerController::ClientUpdateARWorldData_Implementation(int32 Offset, const TArray<uint8>& Buffer)
{
UE_LOG(LogAR, Verbose, TEXT("Client received ClientUpdateARWorldData(%d, %d)"), Offset, Buffer.Num());
GetGameState()->UpdateARWorldData(Offset, Buffer.GetData(), Buffer.Num());
}