Skip to content

Commit e35963e

Browse files
committed
Skip unsupported icon formats in PackageWrapper.LoadIconAsync
The icon cache (IconCacheEngine.MimeToExtension) writes files in formats Avalonia's Skia Bitmap cannot decode: SVG, AVIF, ICO, TIFF. Passing such a file to `new Bitmap(uri.LocalPath)` throws ArgumentException("Unable to load bitmap from provided data"). The exception is caught and the failure is cached, but Rider's debugger surfaces every first-chance throw, so users see a flood of stack traces whenever the package list brings new rows with non-raster icons into view (e.g. after typing in the search bar). Whitelist PNG/JPEG/GIF/BMP/WebP — the formats Skia can actually decode — and short-circuit unsupported extensions to a cached-null result. The package falls back to its manager source icon, same as before.
1 parent 271ac3e commit e35963e

1 file changed

Lines changed: 18 additions & 0 deletions

File tree

src/UniGetUI.Avalonia/Models/PackageCollections.cs

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -201,6 +201,13 @@ private async Task LoadIconAsync()
201201

202202
if (uri.IsFile)
203203
{
204+
if (!IsSkiaDecodableExtension(uri.LocalPath))
205+
{
206+
// Avalonia's Bitmap (Skia) can't decode SVG/AVIF/ICO/TIFF — the
207+
// icon cache may produce those. Reject upfront so we don't throw.
208+
_iconCache[hash] = null;
209+
return;
210+
}
204211
bitmap = await Task.Run(() => new Bitmap(uri.LocalPath)).ConfigureAwait(false);
205212
}
206213
else if (uri.Scheme is "http" or "https")
@@ -223,6 +230,17 @@ private async Task LoadIconAsync()
223230
catch { _iconCache[hash] = null; }
224231
}
225232

233+
private static bool IsSkiaDecodableExtension(string path)
234+
{
235+
string ext = Path.GetExtension(path);
236+
return ext.Equals(".png", StringComparison.OrdinalIgnoreCase)
237+
|| ext.Equals(".jpg", StringComparison.OrdinalIgnoreCase)
238+
|| ext.Equals(".jpeg", StringComparison.OrdinalIgnoreCase)
239+
|| ext.Equals(".gif", StringComparison.OrdinalIgnoreCase)
240+
|| ext.Equals(".bmp", StringComparison.OrdinalIgnoreCase)
241+
|| ext.Equals(".webp", StringComparison.OrdinalIgnoreCase);
242+
}
243+
226244
private void Package_PropertyChanged(object? sender, PropertyChangedEventArgs e)
227245
{
228246
if (e.PropertyName == nameof(Package.Tag))

0 commit comments

Comments
 (0)