Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Sanitize vessel filenames #131

Merged
merged 1 commit into from
Jan 17, 2022

Conversation

HebaruSan
Copy link

Hi @dkavolis! A user posted a log on the forum, and I noticed this while investigating:

https://forum.kerbalspaceprogram.com/index.php?/topic/206468-having-unexpected-mark-stack-overflow-and-other-unexpected-crashes-in-a-modded-install/

Also submitted Boris-Barboris/AtmosphereAutopilot#29 for the same problem in another mod.

Problem

If a user on Windows puts a " character in a vessel's name, this is seen in the log:

[EXC 16:28:19.888] ArgumentException: Illegal characters in path.
	System.IO.Path.Combine (System.String path1, System.String path2) (at <9577ac7a62ef43179789031239ba8798>:0)
	FerramAerospaceResearch.FARGUI.FARFlightGUI.FlightDataLogger.GetFilename () (at <5703ae4062a541a09eeee98e1716f5d5>:0)
	FerramAerospaceResearch.FARGUI.FARFlightGUI.FlightDataLogger.CreateLogger (Vessel vessel) (at <5703ae4062a541a09eeee98e1716f5d5>:0)
	FerramAerospaceResearch.FARGUI.FARFlightGUI.FlightGUI.OnStart () (at <5703ae4062a541a09eeee98e1716f5d5>:0)
	VesselModule.Start () (at <39c0323fb6b449a4aaf3465c00ed3c8d>:0)
	UnityEngine.DebugLogHandler:LogException(Exception, Object)
	ModuleManager.UnityLogHandle.InterceptLogHandler:LogException(Exception, Object)
	UnityEngine.Debug:CallOverridenDebugHandler(Exception, Object)

This causes the serialization to fail, which may be cascading into other problems as well:

I have indeed noticed strange behavior on the behalf of FAR (as in the GUI not displaying any information)

Cause

Windows doesn't allow certain characters in filenames, including ", and FARc is trying to put user input into a filename without sanitizing it.

Changes

Now this filename is passed through KSPUtil.SanitizeFilename before use (the same thing the stock game does with .craft files), so it will not contain illegal characters.

@dkavolis
Copy link
Owner

Thanks for the PR!

@dkavolis dkavolis merged commit 2b7fb26 into dkavolis:master Jan 17, 2022
@HebaruSan HebaruSan deleted the fix/sanitize-vessel-filenames branch January 17, 2022 20:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants