The Free Software Media System - Server Backend & API
Add fuzzing infra
Bond_009f7392394fdcf
diff --git a/.gitignore b/.gitignoreindex 7cd3d0068a..252210e57c 100644--- a/.gitignore+++ b/.gitignore@@ -268,6 +268,7 @@ doc/# Deployment artifactsdist*.exe+*.dll# BenchmarkDotNet artifactsBenchmarkDotNet.Artifactsdiff --git a/fuzz/.gitignore b/fuzz/.gitignorenew file mode 100644index 0000000000..652de0a45f--- /dev/null+++ b/fuzz/.gitignore@@ -0,0 +1 @@+Findingsdiff --git a/fuzz/Emby.Server.Implementations.Fuzz/Emby.Server.Implementations.Fuzz.csproj b/fuzz/Emby.Server.Implementations.Fuzz/Emby.Server.Implementations.Fuzz.csprojnew file mode 100644index 0000000000..791cb140db--- /dev/null+++ b/fuzz/Emby.Server.Implementations.Fuzz/Emby.Server.Implementations.Fuzz.csproj@@ -0,0 +1,18 @@+<Project Sdk="Microsoft.NET.Sdk">++ <PropertyGroup>+ <OutputType>Exe</OutputType>+ <TargetFramework>net5.0</TargetFramework>+ </PropertyGroup>++ <ItemGroup>+ <Reference Include="Emby.Server.Implementations">+ <HintPath>Emby.Server.Implementations.dll</HintPath>+ </Reference>+ </ItemGroup>++ <ItemGroup>+ <PackageReference Include="SharpFuzz" Version="1.6.2" />+ </ItemGroup>++</Project>diff --git a/fuzz/Emby.Server.Implementations.Fuzz/Program.cs b/fuzz/Emby.Server.Implementations.Fuzz/Program.csnew file mode 100644index 0000000000..a4a6f5f54d--- /dev/null+++ b/fuzz/Emby.Server.Implementations.Fuzz/Program.cs@@ -0,0 +1,32 @@+using System;+using Emby.Server.Implementations.Library;+using SharpFuzz;++namespace Emby.Server.Implementations.Fuzz+{+ public static class Program+ {+ public static void Main(string[] args)+ {+ switch (args[0])+ {+ case "PathExtensions.TryReplaceSubPath": Run(PathExtensions_TryReplaceSubPath); return;+ default: throw new ArgumentException($"Unknown fuzzing function: {args[0]}");+ }+ }++ private static void Run(Action<string> action) => Fuzzer.OutOfProcess.Run(action);++ private static void PathExtensions_TryReplaceSubPath(string data)+ {+ // Stupid, but it worked+ var parts = data.Split(':');+ if (parts.Length != 3)+ {+ return;+ }++ _ = PathExtensions.TryReplaceSubPath(parts[0], parts[1], parts[2], out _);+ }+ }+}diff --git a/fuzz/Emby.Server.Implementations.Fuzz/Testcases/PathExtensions.TryReplaceSubPath/test1.txt b/fuzz/Emby.Server.Implementations.Fuzz/Testcases/PathExtensions.TryReplaceSubPath/test1.txtnew file mode 100644index 0000000000..aacf973d67--- /dev/null+++ b/fuzz/Emby.Server.Implementations.Fuzz/Testcases/PathExtensions.TryReplaceSubPath/test1.txt@@ -0,0 +1 @@+/fuzz/Emby.Server.Implementations.Fuzz/Testcases/PathExtensions.TryReplaceSubPath/test1.txt/:/home/bond/dev/jellyfin/:/srv/jellyfin/diff --git a/fuzz/Emby.Server.Implementations.Fuzz/fuzz.sh b/fuzz/Emby.Server.Implementations.Fuzz/fuzz.shnew file mode 100755index 0000000000..244f734026--- /dev/null+++ b/fuzz/Emby.Server.Implementations.Fuzz/fuzz.sh@@ -0,0 +1,11 @@+#!/bin/sh++set -e++dotnet build -c Release ../../Emby.Server.Implementations/Emby.Server.Implementations.csproj --output bin+sharpfuzz bin/Emby.Server.Implementations.dll+cp bin/Emby.Server.Implementations.dll .++dotnet build+mkdir -p Findings+AFL_SKIP_BIN_CHECK=1 afl-fuzz -i "Testcases/$1" -o "Findings/$1" -t 5000 -m 10240 dotnet bin/Debug/net5.0/Emby.Server.Implementations.Fuzz.dll "$1"diff --git a/fuzz/Jellyfin.Server.Fuzz/Jellyfin.Server.Fuzz.csproj b/fuzz/Jellyfin.Server.Fuzz/Jellyfin.Server.Fuzz.csprojnew file mode 100644index 0000000000..6fcfbae0e6--- /dev/null+++ b/fuzz/Jellyfin.Server.Fuzz/Jellyfin.Server.Fuzz.csproj@@ -0,0 +1,22 @@+<Project Sdk="Microsoft.NET.Sdk.Web">++ <PropertyGroup>+ <OutputType>Exe</OutputType>+ <TargetFramework>net5.0</TargetFramework>+ </PropertyGroup>++ <ItemGroup>+ <Reference Include="Jellyfin.Server">+ <HintPath>jellyfin.dll</HintPath>+ </Reference>+ </ItemGroup>++ <ItemGroup>+ <ProjectReference Include="../../MediaBrowser.Common/MediaBrowser.Common.csproj" />+ </ItemGroup>++ <ItemGroup>+ <PackageReference Include="SharpFuzz" Version="1.6.2" />+ </ItemGroup>++</Project>diff --git a/fuzz/Jellyfin.Server.Fuzz/Program.cs b/fuzz/Jellyfin.Server.Fuzz/Program.csnew file mode 100644index 0000000000..e47286c131--- /dev/null+++ b/fuzz/Jellyfin.Server.Fuzz/Program.cs@@ -0,0 +1,33 @@+using System;+using System.Collections.Generic;+using Jellyfin.Server.Middleware;+using Microsoft.AspNetCore.Http;+using Microsoft.AspNetCore.Http.Features;+using Microsoft.Extensions.Primitives;+using SharpFuzz;++namespace Emby.Server.Implementations.Fuzz+{+ public static class Program+ {+ public static void Main(string[] args)+ {+ switch (args[0])+ {+ case "UrlDecodeQueryFeature": Run(UrlDecodeQueryFeature); return;+ default: throw new ArgumentException($"Unknown fuzzing function: {args[0]}");+ }+ }++ private static void Run(Action<string> action) => Fuzzer.OutOfProcess.Run(action);++ private static void UrlDecodeQueryFeature(string data)+ {+ var dict = new Dictionary<string, StringValues>+ {+ { data, StringValues.Empty }+ };+ _ = new UrlDecodeQueryFeature(new QueryFeature(new QueryCollection(dict)));+ }+ }+}diff --git a/fuzz/Jellyfin.Server.Fuzz/Testcases/UrlDecodeQueryFeature/test1.txt b/fuzz/Jellyfin.Server.Fuzz/Testcases/UrlDecodeQueryFeature/test1.txtnew file mode 100644index 0000000000..73f356b936--- /dev/null+++ b/fuzz/Jellyfin.Server.Fuzz/Testcases/UrlDecodeQueryFeature/test1.txt@@ -0,0 +1 @@+a%3D1%26b%3D2%26c%3D3diff --git a/fuzz/Jellyfin.Server.Fuzz/fuzz.sh b/fuzz/Jellyfin.Server.Fuzz/fuzz.shnew file mode 100755index 0000000000..ad81e2c355--- /dev/null+++ b/fuzz/Jellyfin.Server.Fuzz/fuzz.sh@@ -0,0 +1,11 @@+#!/bin/sh++set -e++dotnet build -c Release ../../Jellyfin.Server/Jellyfin.Server.csproj --output bin+sharpfuzz bin/jellyfin.dll+cp bin/jellyfin.dll .++dotnet build+mkdir -p Findings+AFL_SKIP_BIN_CHECK=1 afl-fuzz -i "Testcases/$1" -o "Findings/$1" -t 5000 -m 10240 dotnet bin/Debug/net5.0/Jellyfin.Server.Fuzz.dll "$1"