Skip to content

[fix] fix build failure from package vulnerability - #149

Open
thando-ndlovu wants to merge 1 commit into
paulirwin:masterfrom
thando-ndlovu:master
Open

[fix] fix build failure from package vulnerability#149
thando-ndlovu wants to merge 1 commit into
paulirwin:masterfrom
thando-ndlovu:master

Conversation

@thando-ndlovu

Copy link
Copy Markdown

Package 'Tmds.DBus.Protocol' explicitly added as build fails from transient package usage. `Warning As Error: Package 'Tmds.DBus.Protocol' 0.21.2 has a known high severity vulnerability, GHSA-xrw6-gwf8-vvr9

File JavaToCSharpGui\ViewModels\MainWindowViewModel.cs
Line187 has been changed from
int subStartIndex = dir.FullName.Length; to
int subStartIndex = dir.FullName.Length - 1;

  • Fixes exception 'startIndex cannot be larger than length of string. (Parameter 'startIndex')' thrown on line193, string jOutPath = $"{outDirFullName}{jPath[subStartIndex..]}"; when sub directories are not present or .java files are directly under chosen directory
  • Fixes improper directory duplicate creation when sub dirs are present.
    Previous result takes maindir/subdir_one/file_one.java and creates
    maindir/maindir_csharp_outputsubdir_one/file_one.java &
    maindir/maindir_csharp_output/subdir_one/file_one.java

current result takes
maindir/subdir_one/file_one.java and cretes only
maindir/maindir_csharp_output/subdir_one/file_one.java

packageid:Tmds.DBus.Protocol Added
	Warning As Error: Package 'Tmds.DBus.Protocol' 0.21.2 has a known high severity vulnerability, GHSA-xrw6-gwf8-vvr9
@paulirwin

Copy link
Copy Markdown
Owner

@thando-ndlovu Thanks for the contribution! Unfortunately this PR needs a few updates:

First, this PR conflates two things: the exception fix you experienced, and the build failure. I did not want to fix the build failure by pinning that specific dependency; so I fixed that separately in #150. You can revert that part of this PR and make this PR just about the exception fix.

Second, I would encourage you to check out a new branch from master for all pull requests. That will make it easier for you to submit parallel PRs, allow maintainers to update the PR without affecting your master branch, and more easily update your master branch once this is merged without having to force-push.

Third, the fix for the exception is incomplete. This now fixes it for a trailing separator, but breaks it for cases where there is no trailing separator. A more robust fix would be to use Path.GetRelativePath which handles trailing separators, casing, and separator normalization for you. For example:

string outDirFullName = outDir.FullName;

foreach (var jFile in FolderInputFiles.Where(static x => x.Directory is not null))
{
    // ! null checked above
    string jPath = jFile.Directory!.FullName;
    string relativePath = Path.GetRelativePath(dir.FullName, jPath);
    string jOutPath = Path.Combine(outDirFullName, relativePath);
    ...
}

If you are not available or interested in making this update, just let me know and I can fix it. I would have done it myself; I just don't want to force-push your master branch. Thanks!

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