Skip to content

Commit 8adf11b

Browse files
committed
fix: crash when create image from a empty stream
1 parent 75f6087 commit 8adf11b

File tree

3 files changed

+5
-5
lines changed

3 files changed

+5
-5
lines changed

src/Commands/QueryFileContent.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,23 +17,23 @@ public static Stream Run(string repo, string revision, string file)
1717
starter.WindowStyle = ProcessWindowStyle.Hidden;
1818
starter.RedirectStandardOutput = true;
1919

20+
var stream = new MemoryStream();
2021
try
2122
{
22-
var stream = new MemoryStream();
2323
var proc = new Process() { StartInfo = starter };
2424
proc.Start();
2525
proc.StandardOutput.BaseStream.CopyTo(stream);
2626
proc.WaitForExit();
2727
proc.Close();
2828

2929
stream.Position = 0;
30-
return stream;
3130
}
3231
catch (Exception e)
3332
{
3433
App.RaiseException(repo, $"Failed to query file content: {e}");
35-
return null;
3634
}
35+
36+
return stream;
3737
}
3838
}
3939
}

src/ViewModels/CommitDetail.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -475,7 +475,7 @@ private void RefreshViewRevisionFile(Models.Object file)
475475
if (IMG_EXTS.Contains(ext))
476476
{
477477
var stream = Commands.QueryFileContent.Run(_repo, _commit.SHA, file.Path);
478-
var bitmap = stream != null ? new Bitmap(stream) : null as Bitmap;
478+
var bitmap = stream.Length > 0 ? new Bitmap(stream) : null;
479479
Dispatcher.UIThread.Invoke(() =>
480480
{
481481
ViewRevisionFileContent = new Models.RevisionImageFile() { Image = bitmap };

src/ViewModels/DiffContext.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -166,7 +166,7 @@ public void OpenExternalMergeTool()
166166
private Bitmap BitmapFromRevisionFile(string repo, string revision, string file)
167167
{
168168
var stream = Commands.QueryFileContent.Run(repo, revision, file);
169-
return stream != null ? new Bitmap(stream) : null;
169+
return stream.Length > 0 ? new Bitmap(stream) : null;
170170
}
171171

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

0 commit comments

Comments
 (0)