From ac91fdafed8a6b0f9c7c018051d19c8e6bb36870 Mon Sep 17 00:00:00 2001 From: Stephen Toub Date: Tue, 4 Jan 2022 12:19:55 -0500 Subject: [PATCH] Fix null ref for null Stream input in Icon.Save --- .../src/System/Drawing/Icon.Windows.NoCOMWrappers.cs | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/src/libraries/System.Drawing.Common/src/System/Drawing/Icon.Windows.NoCOMWrappers.cs b/src/libraries/System.Drawing.Common/src/System/Drawing/Icon.Windows.NoCOMWrappers.cs index 34a5d19a0d9c8..124ce9f3a7bda 100644 --- a/src/libraries/System.Drawing.Common/src/System/Drawing/Icon.Windows.NoCOMWrappers.cs +++ b/src/libraries/System.Drawing.Common/src/System/Drawing/Icon.Windows.NoCOMWrappers.cs @@ -15,6 +15,7 @@ public void Save(Stream outputStream) { if (_iconData != null) { + ArgumentNullException.ThrowIfNull(outputStream); outputStream.Write(_iconData, 0, _iconData.Length); } else @@ -32,9 +33,7 @@ public void Save(Stream outputStream) { try { - if (outputStream == null) - throw new ArgumentNullException(nameof(outputStream)); - + ArgumentNullException.ThrowIfNull(outputStream); picture.SaveAsFile(new GPStream(outputStream, makeSeekable: false), -1, out int temp); } finally