Fix BlackholeController exception when torrent name is very long (#10889)

This commit is contained in:
Michaël Fortin 2021-01-25 13:50:31 -05:00 committed by GitHub
parent 0b4d1712c5
commit 6fba522075
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 11 additions and 1 deletions

View File

@ -88,7 +88,17 @@ namespace Jackett.Server.Controllers
else
fileName += "-" + StringUtil.MakeValidFileName(file + fileExtension, '_', false); // call MakeValidFileName() again to avoid any possibility of path traversal attacks
System.IO.File.WriteAllBytes(Path.Combine(serverConfig.BlackholeDir, fileName), downloadBytes);
try
{
System.IO.File.WriteAllBytes(Path.Combine(serverConfig.BlackholeDir, fileName), downloadBytes);
}
catch (IOException)
{
// Sometimes a torrent's name is very long which causes an exception when writing the file to disk.
// In this specific case, use a GUID instead of the torrent's name.
System.IO.File.WriteAllBytes(Path.Combine(serverConfig.BlackholeDir, Guid.NewGuid() + fileExtension), downloadBytes);
}
jsonReply["result"] = "success";
}
catch (Exception e)