improve BEncode error handling: Pull in changes from master

3468e7d404
This commit is contained in:
flightlevel
2018-06-16 18:40:31 +10:00
parent a25eb7f951
commit 1a14e8dd4b

View File

@@ -68,9 +68,19 @@ namespace Jackett.Server.Controllers
} }
// This will fix torrents where the keys are not sorted, and thereby not supported by Sonarr. // This will fix torrents where the keys are not sorted, and thereby not supported by Sonarr.
var parser = new BencodeParser(); byte[] sortedDownloadBytes = null;
var torrentDictionary = parser.Parse(downloadBytes); try
byte[] sortedDownloadBytes = torrentDictionary.EncodeAsBytes(); {
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 string fileName = StringUtil.MakeValidFileName(file, '_', false) + ".torrent"; // call MakeValidFileName again to avoid any kind of injection attack