microsoft / sarif-visualstudio-extension

SARIF Microsoft Visual Studio Viewer Extension
MIT License
46 stars 19 forks source link

Exception when navigating to binary file #124

Open ghost opened 4 years ago

ghost commented 4 years ago
  1. Load the sample SARIF file EmbbeddedBinaryContent.sarif.

  2. Double-click on its single result.

Expected: The file loads in a binary editor, and the range of bytes specified in the result's region are highlighted.

Actual: The extension throws an exception:

System.ArgumentOutOfRangeException: The value cannot be negative.
Parameter name: offset
Actual value was -1.
   at Microsoft.CodeAnalysis.Sarif.NewLineIndex.GetOffsetInfoForOffset(Int32 offset)
   at Microsoft.CodeAnalysis.Sarif.FileRegionsCache.PopulatePropertiesFromCharOffsetAndLength(NewLineIndex newLineIndex, Region region)
   at Microsoft.CodeAnalysis.Sarif.FileRegionsCache.PopulateTextRegionProperties(NewLineIndex lineIndex, Region inputRegion, String fileText, Boolean populateSnippet)
   at Microsoft.Sarif.Viewer.SarifErrorListItem.RemapFilePath(String originalPath, String remappedPath) in D:\a\1\s\src\Sarif.Viewer.VisualStudio\Models\SarifErrorListItem.cs:line 470
   at Microsoft.Sarif.Viewer.CodeAnalysisResultManager.RemapFileNames(IList`1 sarifErrors, String originalPath, String remappedPath) in D:\a\1\s\src\Sarif.Viewer.VisualStudio\CodeAnalysisResultManager.cs:line 543
   at Microsoft.Sarif.Viewer.CodeAnalysisResultManager.TryRebaselineAllSarifErrors(Int32 runId, String uriBaseId, String originalFilename) in D:\a\1\s\src\Sarif.Viewer.VisualStudio\CodeAnalysisResultManager.cs:line 336
   at Microsoft.Sarif.Viewer.ResultTextMarker.NavigateTo(Boolean usePreviewPane) in D:\a\1\s\src\Sarif.Viewer.VisualStudio\ResultTextMarker.cs:line 71
   at Microsoft.Sarif.Viewer.ErrorList.SarifTableControlEventProcessorProvider.EventProcessor.PreprocessNavigate(ITableEntryHandle entryHandle, TableEntryNavigateEventArgs e) in D:\a\1\s\src\Sarif.Viewer.VisualStudio\ErrorList\SarifTableControlEventProcessorProvider.cs:line 96
   at Microsoft.VisualStudio.Shell.TableControl.Implementation.TableControlEventManager.<>c__DisplayClass40_0.<OnEntryElementNavigate>b__2(ITableControlEventProcessor p, ITableEntryHandle entry)
   at Microsoft.VisualStudio.Shell.TableControl.Implementation.TableControlEventManager.<>c__DisplayClass60_1`1.<EventProcessorHandler>b__0()
   at Microsoft.VisualStudio.Text.Utilities.GuardedOperations.CallExtensionPoint(Object errorSource, Action call)
--- End of stack trace from previous location where exception was thrown ---
   at Microsoft.VisualStudio.Telemetry.WindowsErrorReporting.WatsonReport.GetClrWatsonExceptionInfo(Exception exceptionObject)

Note: The binary content in the example is the byte array { 0x01, 0x02, 0x03, 0x04, 0x05 }, encoded in MIME Base64 as "AQIDBAU=". If you edit the sample so that the binary content is { 0x01, 0x02, 0x03 } by changing the string to "AQID", the extension doesn't crash. But it loads the file into a text editor and highlights -- something -- which is still not the right behavior.

yongyan-gh commented 2 years ago

@eddynaka I created a sample .sarif file based on the content mentioned by Larry since the sample sarif file does not exist anymore.

I am able to navigate to the binary content embedded into .sarif file in latest Sarif Viewer.

The region corresponding for binary content should include charOffset and charLength. If the offset and length are specified within a valid range, the viewer can open the binary content and highlight the correct portion specified by region.

If set the region's charOffset to an invalid value like -1, and try to navigate to the result, viewer throws same exception in original issue, and it will not open the source binary file in VS. The behavior is same as navigate to a text content file with region has invalid start line/number.

Let me know what do you think?

EmbeddedBinaryTests.zip