microsoft / sarif-sdk

.NET code and supporting files for working with the 'Static Analysis Results Interchange Format' (SARIF, see https://github.com/oasis-tcs/sarif-spec)
Other
194 stars 93 forks source link

File Size enumeration exception #2663

Closed suvamM closed 1 year ago

suvamM commented 1 year ago

This PR makes the following fixes:

  1. EnumeratedArtifact class throws an exception while analyzing certain Linux files. An example file path which reproduces the error is D:/test/file. The issue arises in the get_SizeInBytes method:

    this.sizeInBytes = Uri!.IsFile
                    ? (ulong)FileSystem.FileInfoLength(Uri.LocalPath)
                    : (ulong?)null;

    The example file path above is treated as a relative URI, which causes exceptions in Uri.IsFile and Uri.LocalPath. The change in this PR checks if the path associated with Uri.GetFilePath() has the attributes of a file or directory (which is expected work across Windows and Linux). I tested this change by doing an analysis in Linux, and no exceptions are thrown.

  2. The post-build task of Coyote binary instrumentation does not work in Linux, since it is a powershell script. This causes a build failure in Linux. This PR adds a condition in the post-build task to perform the rewriting only in Windows.

schlaman-ms commented 1 year ago

What about this location for same issue?


In reply to: 1532298368


Refers to: src/Sarif/EnumeratedArtifact.cs:43 in 1909293. [](commit_id = 1909293f63b23109b6947ecce63dbd866011cd98, deletion_comment = False)

schlaman-ms commented 1 year ago

In another method, FormatForVisualStudio(), there is this:

string path = uri.IsAbsoluteUri && uri.IsFile ? uri.LocalPath : uri.ToString();

Actually in all the other locations where .IsFile is called it has the above pattern for uri.IsAbsoluteUri && uri.IsFile

Isn't this one an issue as well?


In reply to: 1532301809


Refers to: src/Sarif/EnumeratedArtifact.cs:43 in 1909293. [](commit_id = 1909293f63b23109b6947ecce63dbd866011cd98, deletion_comment = False)

suvamM commented 1 year ago

In another method, FormatForVisualStudio(), there is this:

string path = uri.IsAbsoluteUri && uri.IsFile ? uri.LocalPath : uri.ToString();

Actually in all the other locations where .IsFile is called it has the above pattern for uri.IsAbsoluteUri && uri.IsFile

Isn't this one an issue as well?

Refers to: src/Sarif/EnumeratedArtifact.cs:43 in 1909293. [](commit_id = 1909293, deletion_comment = False)

@schlaman-ms Do we have an example where this causes an issue?