Fix crashes due to malicious RPFs

RpfFile:
- Limit RPF entry names to 256 characters because long names can cause the RPFExplorer to freeze when opening its directory.
- Skip RPFs with paths longer that 5000 characters, which are probably an attempt to make CW run out-of-memory.

ExploreForm:
- Use `Path.GetExtension` directly instead of `FileInfo` to prevent `PathTooLongException`s.
- Check for invalid characters in file names to prevent `ArgumentException`s.
This commit is contained in:
alexguirre
2023-08-12 10:03:28 +02:00
Unverified
parent 9d76f2c6c4
commit 118305e481
2 changed files with 13 additions and 3 deletions
+7 -2
View File
@@ -25,6 +25,7 @@ namespace CodeWalker
private volatile bool Ready = false;
private Dictionary<string, FileTypeInfo> FileTypes;
private readonly char[] InvalidFileNameChars = Path.GetInvalidFileNameChars();
private MainTreeFolder RootFolder;
private List<MainTreeFolder> ExtraRootFolders = new List<MainTreeFolder>();
@@ -333,8 +334,12 @@ namespace CodeWalker
}
public FileTypeInfo GetFileType(string fn)
{
var fi = new FileInfo(fn);
var ext = fi.Extension.ToLowerInvariant();
if (fn.IndexOfAny(InvalidFileNameChars) != -1)
{
return FileTypes[""];
}
var ext = Path.GetExtension(fn).ToLowerInvariant();
if (!string.IsNullOrEmpty(ext))
{
FileTypeInfo ft;