mirror of
https://mirror.ghproxy.com/https://github.com/dexyfex/CodeWalker
synced 2024-11-25 08:22:54 +08:00
Merge pull request #211 from alexguirre/rpf
Fix crashes due to malicious RPFs
This commit is contained in:
commit
ae9498f7d5
@ -215,6 +215,11 @@ namespace CodeWalker.GameFiles
|
|||||||
|
|
||||||
namesrdr.Position = e.NameOffset;
|
namesrdr.Position = e.NameOffset;
|
||||||
e.Name = namesrdr.ReadString();
|
e.Name = namesrdr.ReadString();
|
||||||
|
if (e.Name.Length > 256)
|
||||||
|
{
|
||||||
|
// long names can freeze the RPFExplorer
|
||||||
|
e.Name = e.Name.Substring(0, 256);
|
||||||
|
}
|
||||||
e.NameLower = e.Name.ToLowerInvariant();
|
e.NameLower = e.Name.ToLowerInvariant();
|
||||||
|
|
||||||
if ((e is RpfFileEntry) && string.IsNullOrEmpty(e.Name))
|
if ((e is RpfFileEntry) && string.IsNullOrEmpty(e.Name))
|
||||||
@ -312,7 +317,7 @@ namespace CodeWalker.GameFiles
|
|||||||
|
|
||||||
//search all the sub resources for YSC files. (recurse!)
|
//search all the sub resources for YSC files. (recurse!)
|
||||||
string lname = binentry.NameLower;
|
string lname = binentry.NameLower;
|
||||||
if (lname.EndsWith(".rpf"))
|
if (lname.EndsWith(".rpf") && binentry.Path.Length < 5000) // a long path is most likely an attempt to crash CW, so skip it
|
||||||
{
|
{
|
||||||
br.BaseStream.Position = StartPos + ((long)binentry.FileOffset * 512);
|
br.BaseStream.Position = StartPos + ((long)binentry.FileOffset * 512);
|
||||||
|
|
||||||
|
@ -25,6 +25,7 @@ namespace CodeWalker
|
|||||||
private volatile bool Ready = false;
|
private volatile bool Ready = false;
|
||||||
|
|
||||||
private Dictionary<string, FileTypeInfo> FileTypes;
|
private Dictionary<string, FileTypeInfo> FileTypes;
|
||||||
|
private readonly char[] InvalidFileNameChars = Path.GetInvalidFileNameChars();
|
||||||
|
|
||||||
private MainTreeFolder RootFolder;
|
private MainTreeFolder RootFolder;
|
||||||
private List<MainTreeFolder> ExtraRootFolders = new List<MainTreeFolder>();
|
private List<MainTreeFolder> ExtraRootFolders = new List<MainTreeFolder>();
|
||||||
@ -333,8 +334,12 @@ namespace CodeWalker
|
|||||||
}
|
}
|
||||||
public FileTypeInfo GetFileType(string fn)
|
public FileTypeInfo GetFileType(string fn)
|
||||||
{
|
{
|
||||||
var fi = new FileInfo(fn);
|
if (fn.IndexOfAny(InvalidFileNameChars) != -1)
|
||||||
var ext = fi.Extension.ToLowerInvariant();
|
{
|
||||||
|
return FileTypes[""];
|
||||||
|
}
|
||||||
|
|
||||||
|
var ext = Path.GetExtension(fn).ToLowerInvariant();
|
||||||
if (!string.IsNullOrEmpty(ext))
|
if (!string.IsNullOrEmpty(ext))
|
||||||
{
|
{
|
||||||
FileTypeInfo ft;
|
FileTypeInfo ft;
|
||||||
|
Loading…
Reference in New Issue
Block a user