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

Handle backslashes in ZIP paths #3893

Merged
merged 2 commits into from
Dec 13, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 7 additions & 2 deletions Core/Types/ModuleInstallDescriptor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -427,8 +427,13 @@ public List<InstallableFile> FindInstallableFiles(ZipFile zipfile, GameInstance
// Surely there's a better way, although this is fast enough we may not care.
foreach (ZipEntry entry in zipfile)
{
// Backslashes are not allowed in filenames according to the ZIP spec,
// but there's a non-conformant PowerShell tool that uses them anyway.
// Try to accommodate those mods.
string entryName = entry.Name.Replace('\\', '/');

// Skips dirs and things not prescribed by our install stanza.
if (!IsWanted(entry.Name, shortestMatch))
if (!IsWanted(entryName, shortestMatch))
{
continue;
}
Expand All @@ -447,7 +452,7 @@ public List<InstallableFile> FindInstallableFiles(ZipFile zipfile, GameInstance
// Get the full name of the file.
// Update our file info with the install location
file_info.destination = TransformOutputName(
ksp.game, entry.Name, installDir, @as);
ksp.game, entryName, installDir, @as);
file_info.makedir = AllowDirectoryCreation(
ksp.game,
ksp?.ToRelativeGameDir(file_info.destination)
Expand Down
4 changes: 4 additions & 0 deletions Netkan/Validators/InstallValidator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,10 @@ public void Validate(Metadata metadata)
if (stanza.ContainsKey(propName))
{
string val = (string)stanza[propName];
if (string.IsNullOrEmpty(val))
{
throw new Kraken($"Install property '{propName}' is null or empty");
}
string norm = CKANPathUtils.NormalizePath(val);
if (val != norm)
{
Expand Down
Loading