Skip to content

Commit

Permalink
fix: crash when create image from a empty stream
Browse files Browse the repository at this point in the history
  • Loading branch information
love-linger committed Apr 8, 2024
1 parent 75f6087 commit 8adf11b
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 5 deletions.
6 changes: 3 additions & 3 deletions src/Commands/QueryFileContent.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,23 +17,23 @@ public static Stream Run(string repo, string revision, string file)
starter.WindowStyle = ProcessWindowStyle.Hidden;
starter.RedirectStandardOutput = true;

var stream = new MemoryStream();
try
{
var stream = new MemoryStream();
var proc = new Process() { StartInfo = starter };
proc.Start();
proc.StandardOutput.BaseStream.CopyTo(stream);
proc.WaitForExit();
proc.Close();

stream.Position = 0;
return stream;
}
catch (Exception e)
{
App.RaiseException(repo, $"Failed to query file content: {e}");
return null;
}

return stream;
}
}
}
2 changes: 1 addition & 1 deletion src/ViewModels/CommitDetail.cs
Original file line number Diff line number Diff line change
Expand Up @@ -475,7 +475,7 @@ private void RefreshViewRevisionFile(Models.Object file)
if (IMG_EXTS.Contains(ext))
{
var stream = Commands.QueryFileContent.Run(_repo, _commit.SHA, file.Path);
var bitmap = stream != null ? new Bitmap(stream) : null as Bitmap;
var bitmap = stream.Length > 0 ? new Bitmap(stream) : null;
Dispatcher.UIThread.Invoke(() =>
{
ViewRevisionFileContent = new Models.RevisionImageFile() { Image = bitmap };
Expand Down
2 changes: 1 addition & 1 deletion src/ViewModels/DiffContext.cs
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ public void OpenExternalMergeTool()
private Bitmap BitmapFromRevisionFile(string repo, string revision, string file)
{
var stream = Commands.QueryFileContent.Run(repo, revision, file);
return stream != null ? new Bitmap(stream) : null;
return stream.Length > 0 ? new Bitmap(stream) : null;
}

private static readonly HashSet<string> IMG_EXTS = new HashSet<string>()
Expand Down

0 comments on commit 8adf11b

Please sign in to comment.