aboutsummaryrefslogtreecommitdiff
path: root/src/Jellyfin.Drawing.Skia/SkiaEncoder.cs
diff options
context:
space:
mode:
authorqueukat <75810528+queukat@users.noreply.github.com>2025-07-18 01:19:33 +0200
committerGitHub <noreply@github.com>2025-07-17 17:19:33 -0600
commitaa77dfb92dded85eeac6b480f09cb2119a9c5a56 (patch)
treea9d1637284bec781d634f6f87ad105e64de780cf /src/Jellyfin.Drawing.Skia/SkiaEncoder.cs
parent2ad37fe021ca50b9309ab9b04dc8d02282ea1acd (diff)
Drawing: make SkiaEncoder more robust when reading image dimensions (#14481)
Diffstat (limited to 'src/Jellyfin.Drawing.Skia/SkiaEncoder.cs')
-rw-r--r--src/Jellyfin.Drawing.Skia/SkiaEncoder.cs33
1 files changed, 31 insertions, 2 deletions
diff --git a/src/Jellyfin.Drawing.Skia/SkiaEncoder.cs b/src/Jellyfin.Drawing.Skia/SkiaEncoder.cs
index 4626bc914..503e2f941 100644
--- a/src/Jellyfin.Drawing.Skia/SkiaEncoder.cs
+++ b/src/Jellyfin.Drawing.Skia/SkiaEncoder.cs
@@ -202,18 +202,47 @@ public class SkiaEncoder : IImageEncoder
}
}
- using var codec = SKCodec.Create(path, out SKCodecResult result);
+ var safePath = NormalizePath(path);
+ if (new FileInfo(safePath).Length == 0)
+ {
+ _logger.LogDebug("Skip zero‑byte image {FilePath}", path);
+ return default;
+ }
+
+ using var codec = SKCodec.Create(safePath, out var result);
+
switch (result)
{
case SKCodecResult.Success:
+ // Skia/SkiaSharp edge‑case: when the image header is parsed but the actual pixel
+ // decode fails (truncated JPEG/PNG, exotic ICC/EXIF, CMYK without color‑transform, etc.)
+ // `SKCodec.Create` returns a *non‑null* codec together with
+ // SKCodecResult.InternalError. The header still contains valid dimensions,
+ // which is all we need here – so we fall back to them instead of aborting.
+ // See e.g. Skia bugs #4139, #6092.
+ case SKCodecResult.InternalError when codec is not null:
var info = codec.Info;
return new ImageDimensions(info.Width, info.Height);
+
case SKCodecResult.Unimplemented:
_logger.LogDebug("Image format not supported: {FilePath}", path);
return default;
+
default:
- _logger.LogError("Unable to determine image dimensions for {FilePath}: {SkCodecResult}", path, result);
+ {
+ var boundsInfo = SKBitmap.DecodeBounds(safePath);
+
+ if (boundsInfo.Width > 0 && boundsInfo.Height > 0)
+ {
+ return new ImageDimensions(boundsInfo.Width, boundsInfo.Height);
+ }
+
+ _logger.LogWarning(
+ "Unable to determine image dimensions for {FilePath}: {SkCodecResult}",
+ path,
+ result);
return default;
+ }
}
}