Merge pull request #4550 from crobibero/plugin-repo

Handle invalid plugins
This commit is contained in:
Bill Thornton 2020-11-23 14:17:51 -05:00 committed by GitHub
commit e428614d00
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -6,13 +6,15 @@ using System.Collections.Generic;
using System.IO; using System.IO;
using System.Linq; using System.Linq;
using System.Net.Http; using System.Net.Http;
using System.Runtime.Serialization; using System.Net.Http.Json;
using System.Security.Cryptography; using System.Security.Cryptography;
using System.Text.Json;
using System.Threading; using System.Threading;
using System.Threading.Tasks; using System.Threading.Tasks;
using Jellyfin.Data.Events; using Jellyfin.Data.Events;
using MediaBrowser.Common; using MediaBrowser.Common;
using MediaBrowser.Common.Configuration; using MediaBrowser.Common.Configuration;
using MediaBrowser.Common.Json;
using MediaBrowser.Common.Net; using MediaBrowser.Common.Net;
using MediaBrowser.Common.Plugins; using MediaBrowser.Common.Plugins;
using MediaBrowser.Common.Updates; using MediaBrowser.Common.Updates;
@ -21,8 +23,6 @@ using MediaBrowser.Controller.Configuration;
using MediaBrowser.Controller.Events; using MediaBrowser.Controller.Events;
using MediaBrowser.Controller.Events.Updates; using MediaBrowser.Controller.Events.Updates;
using MediaBrowser.Model.IO; using MediaBrowser.Model.IO;
using MediaBrowser.Model.Net;
using MediaBrowser.Model.Serialization;
using MediaBrowser.Model.Updates; using MediaBrowser.Model.Updates;
using Microsoft.Extensions.Logging; using Microsoft.Extensions.Logging;
@ -40,9 +40,9 @@ namespace Emby.Server.Implementations.Updates
private readonly IApplicationPaths _appPaths; private readonly IApplicationPaths _appPaths;
private readonly IEventManager _eventManager; private readonly IEventManager _eventManager;
private readonly IHttpClientFactory _httpClientFactory; private readonly IHttpClientFactory _httpClientFactory;
private readonly IJsonSerializer _jsonSerializer;
private readonly IServerConfigurationManager _config; private readonly IServerConfigurationManager _config;
private readonly IFileSystem _fileSystem; private readonly IFileSystem _fileSystem;
private readonly JsonSerializerOptions _jsonSerializerOptions;
/// <summary> /// <summary>
/// Gets the application host. /// Gets the application host.
@ -70,7 +70,6 @@ namespace Emby.Server.Implementations.Updates
IApplicationPaths appPaths, IApplicationPaths appPaths,
IEventManager eventManager, IEventManager eventManager,
IHttpClientFactory httpClientFactory, IHttpClientFactory httpClientFactory,
IJsonSerializer jsonSerializer,
IServerConfigurationManager config, IServerConfigurationManager config,
IFileSystem fileSystem, IFileSystem fileSystem,
IZipClient zipClient) IZipClient zipClient)
@ -83,10 +82,10 @@ namespace Emby.Server.Implementations.Updates
_appPaths = appPaths; _appPaths = appPaths;
_eventManager = eventManager; _eventManager = eventManager;
_httpClientFactory = httpClientFactory; _httpClientFactory = httpClientFactory;
_jsonSerializer = jsonSerializer;
_config = config; _config = config;
_fileSystem = fileSystem; _fileSystem = fileSystem;
_zipClient = zipClient; _zipClient = zipClient;
_jsonSerializerOptions = JsonDefaults.GetOptions();
} }
/// <inheritdoc /> /// <inheritdoc />
@ -97,16 +96,15 @@ namespace Emby.Server.Implementations.Updates
{ {
try try
{ {
using var response = await _httpClientFactory.CreateClient(NamedClient.Default) var packages = await _httpClientFactory.CreateClient(NamedClient.Default)
.GetAsync(new Uri(manifest), cancellationToken).ConfigureAwait(false); .GetFromJsonAsync<List<PackageInfo>>(new Uri(manifest), _jsonSerializerOptions, cancellationToken).ConfigureAwait(false);
await using var stream = await response.Content.ReadAsStreamAsync(cancellationToken).ConfigureAwait(false); if (packages == null)
try
{ {
var package = await _jsonSerializer.DeserializeFromStreamAsync<IList<PackageInfo>>(stream).ConfigureAwait(false); return Array.Empty<PackageInfo>();
}
// Store the repository and repository url with each version, as they may be spread apart. // Store the repository and repository url with each version, as they may be spread apart.
foreach (var entry in package) foreach (var entry in packages)
{ {
foreach (var ver in entry.versions) foreach (var ver in entry.versions)
{ {
@ -115,14 +113,13 @@ namespace Emby.Server.Implementations.Updates
} }
} }
return package; return packages;
} }
catch (SerializationException ex) catch (JsonException ex)
{ {
_logger.LogError(ex, "Failed to deserialize the plugin manifest retrieved from {Manifest}", manifest); _logger.LogError(ex, "Failed to deserialize the plugin manifest retrieved from {Manifest}", manifest);
return Array.Empty<PackageInfo>(); return Array.Empty<PackageInfo>();
} }
}
catch (UriFormatException ex) catch (UriFormatException ex)
{ {
_logger.LogError(ex, "The URL configured for the plugin repository manifest URL is not valid: {Manifest}", manifest); _logger.LogError(ex, "The URL configured for the plugin repository manifest URL is not valid: {Manifest}", manifest);
@ -187,7 +184,13 @@ namespace Emby.Server.Implementations.Updates
// Where repositories have the same content, the details of the first is taken. // Where repositories have the same content, the details of the first is taken.
foreach (var package in await GetPackages(repository.Name, repository.Url, cancellationToken).ConfigureAwait(true)) foreach (var package in await GetPackages(repository.Name, repository.Url, cancellationToken).ConfigureAwait(true))
{ {
var existing = FilterPackages(result, package.name, Guid.Parse(package.guid)).FirstOrDefault(); if (!Guid.TryParse(package.guid, out var packageGuid))
{
// Package doesn't have a valid GUID, skip.
continue;
}
var existing = FilterPackages(result, package.name, packageGuid).FirstOrDefault();
if (existing != null) if (existing != null)
{ {
// Assumption is both lists are ordered, so slot these into the correct place. // Assumption is both lists are ordered, so slot these into the correct place.