Skip to content

Commit

Permalink
Fix a crash when encountering 0 byte .vqa placeholders.
Browse files Browse the repository at this point in the history
  • Loading branch information
Mailaender committed Apr 24, 2022
1 parent 4c08e44 commit 639fce5
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 7 deletions.
7 changes: 5 additions & 2 deletions OpenRA.Mods.Cnc/VideoLoaders/VqaLoader.cs
@@ -1,6 +1,6 @@
#region Copyright & License Information
/*
* Copyright 2007-2021 The OpenRA Developers (see AUTHORS)
* Copyright 2007-2022 The OpenRA Developers (see AUTHORS)
* This file is part of OpenRA, which is free software. It is made
* available to you under the terms of the GNU General Public License
* as published by the Free Software Foundation, either version 3 of
Expand All @@ -21,14 +21,17 @@ public bool TryParseVideo(Stream s, bool useFramePadding, out IVideo video)
{
video = null;

if (s.Length == 0)
return false;

if (!IsWestwoodVqa(s))
return false;

video = new VqaVideo(s, useFramePadding);
return true;
}

bool IsWestwoodVqa(Stream s)
static bool IsWestwoodVqa(Stream s)
{
var start = s.Position;

Expand Down
7 changes: 5 additions & 2 deletions OpenRA.Mods.Cnc/VideoLoaders/WsaLoader.cs
@@ -1,6 +1,6 @@
#region Copyright & License Information
/*
* Copyright 2007-2021 The OpenRA Developers (see AUTHORS)
* Copyright 2007-2022 The OpenRA Developers (see AUTHORS)
* This file is part of OpenRA, which is free software. It is made
* available to you under the terms of the GNU General Public License
* as published by the Free Software Foundation, either version 3 of
Expand All @@ -22,14 +22,17 @@ public bool TryParseVideo(Stream s, bool useFramePadding, out IVideo video)
{
video = null;

if (s.Length == 0)
return false;

if (!IsWsa(s))
return false;

video = new WsaVideo(s, useFramePadding);
return true;
}

bool IsWsa(Stream s)
static bool IsWsa(Stream s)
{
var start = s.Position;

Expand Down
2 changes: 1 addition & 1 deletion OpenRA.Mods.Common/Scripting/Global/MediaGlobal.cs
Expand Up @@ -170,7 +170,7 @@ public bool PlayMovieInRadar(string movie, LuaFunction playComplete = null)
}
catch (FileNotFoundException e)
{
Log.Write("lua", "Couldn't play movie {0}! File doesn't exist.", e.FileName);
Log.Write("lua", $"Couldn't play movie {e.FileName}! File doesn't exist.");
onCompleteRadar();
return false;
}
Expand Down
8 changes: 6 additions & 2 deletions OpenRA.Mods.Common/Widgets/VideoPlayerWidget.cs
@@ -1,6 +1,6 @@
#region Copyright & License Information
/*
* Copyright 2007-2021 The OpenRA Developers (see AUTHORS)
* Copyright 2007-2022 The OpenRA Developers (see AUTHORS)
* This file is part of OpenRA, which is free software. It is made
* available to you under the terms of the GNU General Public License
* as published by the Free Software Foundation, either version 3 of
Expand Down Expand Up @@ -46,14 +46,18 @@ public void Load(string filename)
if (filename == cachedVideoFileName)
return;

var video = VideoLoader.GetVideo(Game.ModData.DefaultFileSystem.Open(filename), true, Game.ModData.VideoLoaders);
var stream = Game.ModData.DefaultFileSystem.Open(filename);
var video = VideoLoader.GetVideo(stream, true, Game.ModData.VideoLoaders);
Open(video);

cachedVideoFileName = filename;
}

public void Open(IVideo video)
{
if (video == null)
return;

this.video = video;

stopped = true;
Expand Down

0 comments on commit 639fce5

Please sign in to comment.