diff --git a/ErsatzTV.Infrastructure/Streaming/Graphics/Script/ScriptElement.cs b/ErsatzTV.Infrastructure/Streaming/Graphics/Script/ScriptElement.cs index a79b68cc8..a93009d71 100644 --- a/ErsatzTV.Infrastructure/Streaming/Graphics/Script/ScriptElement.cs +++ b/ErsatzTV.Infrastructure/Streaming/Graphics/Script/ScriptElement.cs @@ -220,7 +220,7 @@ public class ScriptElement(ScriptGraphicsElement scriptElement, ILogger logger) if (magic != EtvGraphicsMagic || version != 1) { - // TODO: better error handling? + logger.LogWarning("Invalid graphics packet received: magic {Magic}, version {Version}", magic, version); return false; } @@ -243,11 +243,13 @@ public class ScriptElement(ScriptGraphicsElement scriptElement, ILogger logger) } break; case (byte)ScriptPayloadType.Repeat: - uint repeatFrames = BinaryPrimitives.ReadUInt32BigEndian(buffer.First.Span); - _repeatCount = (int)repeatFrames; + Span repeatBytes = stackalloc byte[4]; + buffer.Slice(0, 4).CopyTo(repeatBytes); + _repeatCount = (int)BinaryPrimitives.ReadUInt32BigEndian(repeatBytes); break; case (byte)ScriptPayloadType.Rectangles: // TODO: support rectangles + logger.LogWarning("Unsupported graphics packet type: {Type}", type); success = false; break; } @@ -261,6 +263,11 @@ public class ScriptElement(ScriptGraphicsElement scriptElement, ILogger logger) { _canvasBitmap.Erase(SKColors.Transparent); } + else + { + logger.LogWarning("Unexpected zero-length payload for type {Type}", type); + success = false; + } } return success;