From 1a14e8dd4baf940209a854010a9ca4c8af9bdfa2 Mon Sep 17 00:00:00 2001 From: flightlevel Date: Sat, 16 Jun 2018 18:40:31 +1000 Subject: [PATCH] improve BEncode error handling: Pull in changes from master 3468e7d40428f88537015096ed014d5d1bb8844e --- .../Controllers/DownloadController.cs | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/src/Jackett.Server/Controllers/DownloadController.cs b/src/Jackett.Server/Controllers/DownloadController.cs index c7db678d2..99b8a5fc9 100644 --- a/src/Jackett.Server/Controllers/DownloadController.cs +++ b/src/Jackett.Server/Controllers/DownloadController.cs @@ -68,9 +68,19 @@ namespace Jackett.Server.Controllers } // This will fix torrents where the keys are not sorted, and thereby not supported by Sonarr. - var parser = new BencodeParser(); - var torrentDictionary = parser.Parse(downloadBytes); - byte[] sortedDownloadBytes = torrentDictionary.EncodeAsBytes(); + byte[] sortedDownloadBytes = null; + try + { + var parser = new BencodeParser(); + var torrentDictionary = parser.Parse(downloadBytes); + sortedDownloadBytes = torrentDictionary.EncodeAsBytes(); + } + catch (Exception e) + { + var content = indexer.Encoding.GetString(downloadBytes); + logger.Error(content); + throw new Exception("BencodeParser failed", e); + } string fileName = StringUtil.MakeValidFileName(file, '_', false) + ".torrent"; // call MakeValidFileName again to avoid any kind of injection attack