Skip to content

Commit 1983966

Browse files
committed
Add some more validation to {FFmpeg,RAIntegration}DownloaderForm
see #4275
1 parent 15cdf2d commit 1983966

File tree

4 files changed

+23
-1
lines changed

4 files changed

+23
-1
lines changed

src/BizHawk.Client.EmuHawk/AVOut/FFmpegDownloaderForm.cs

+4
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
using System.IO;
22

33
using BizHawk.Common;
4+
using BizHawk.Common.IOExtensions;
45

56
namespace BizHawk.Client.EmuHawk
67
{
@@ -30,5 +31,8 @@ protected override Stream GetExtractionStream(HawkFile downloaded)
3031

3132
protected override bool PostChmodCheck()
3233
=> FFmpegService.QueryServiceAvailable();
34+
35+
protected override bool PreChmodCheck(FileStream extracted)
36+
=> SHA256Checksum.ComputeDigestHex(extracted.ReadAllBytes()) == FFmpegService.DownloadSHA256Checksum;
3337
}
3438
}

src/BizHawk.Client.EmuHawk/DownloaderForm.cs

+6-1
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,8 @@ private void Download()
104104
//last chance. exiting, don't dump the new file
105105
if (_exiting) return;
106106
exStream.CopyTo(fs);
107+
fs.Position = 0L;
108+
if (!PreChmodCheck(fs)) throw new Exception("download failed (pre-chmod validation)");
107109
fs.Dispose();
108110
if (OSTailoredCode.IsUnixHost)
109111
{
@@ -113,7 +115,7 @@ private void Download()
113115
}
114116

115117
//make sure it worked
116-
if (!PostChmodCheck()) throw new Exception("download failed");
118+
if (!PostChmodCheck()) throw new Exception("download failed (post-chmod validation)");
117119

118120
_succeeded = true;
119121
}
@@ -141,6 +143,9 @@ protected virtual Stream GetExtractionStream(HawkFile downloaded)
141143
protected virtual bool PostChmodCheck()
142144
=> true;
143145

146+
protected virtual bool PreChmodCheck(FileStream extracted)
147+
=> true;
148+
144149
private void btnDownload_Click(object sender, EventArgs e)
145150
{
146151
btnDownload.Text = "Downloading...";

src/BizHawk.Client.EmuHawk/RetroAchievements/RAIntegrationDownloaderForm.cs

+6
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
using BizHawk.Common;
44
using BizHawk.Common.PathExtensions;
5+
using BizHawk.Common.StringExtensions;
56

67
namespace BizHawk.Client.EmuHawk
78
{
@@ -15,6 +16,11 @@ protected override string ComponentName
1516

1617
public RAIntegrationDownloaderForm(string downloadFrom)
1718
{
19+
var downloadDomainName = downloadFrom.RemovePrefix("https://").SubstringBefore('/');
20+
if (!(downloadDomainName is "retroachievements.org" || downloadDomainName.EndsWith(".retroachievements.org")))
21+
{
22+
throw new ArgumentException(paramName: nameof(downloadFrom), message: "untrusted hostname");
23+
}
1824
Description = string.Empty;
1925
DownloadFrom = downloadFrom;
2026
DownloadTo = Path.Combine(PathUtils.DataDirectoryPath, "dll", "RA_Integration-x64.dll");

src/BizHawk.Common/FFmpegService.cs

+7
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,15 @@ public static class FFmpegService
1717

1818
private const string BIN_HOST_URI_WIN_X64 = "https://github.com/TASEmulators/ffmpeg-binaries/raw/master/ffmpeg-4.4.1-static-windows-x64.7z";
1919

20+
private const string BIN_SHA256_LINUX_X64 = "3EA58083710F63BF920B16C7D5D24AE081E7D731F57A656FED11AF0410D4EB48";
21+
22+
private const string BIN_SHA256_WIN_X64 = "8436760AF8F81C95EFF92D854A7684E6D3CEDB872888420359FC45C8EB2664AC";
23+
2024
private const string VERSION = "ffmpeg version 4.4.1";
2125

26+
public static string DownloadSHA256Checksum
27+
=> OSTailoredCode.IsUnixHost ? BIN_SHA256_LINUX_X64 : BIN_SHA256_WIN_X64;
28+
2229
public static string FFmpegPath => Path.Combine(PathUtils.DataDirectoryPath, "dll", OSTailoredCode.IsUnixHost ? "ffmpeg" : "ffmpeg.exe");
2330

2431
public static readonly string Url = OSTailoredCode.IsUnixHost ? BIN_HOST_URI_LINUX_X64 : BIN_HOST_URI_WIN_X64;

0 commit comments

Comments
 (0)