mirror of
https://github.com/jellyfin/jellyfin.git
synced 2026-01-15 15:48:03 +00:00
Backport pull request #15659 from jellyfin/release-10.11.z
Fix thumbnails never deletes from temp folder ( issue #15629 )
Original-merge: 636908fc4d
Merged-by: crobibero <cody@robibe.ro>
Backported-by: Bond_009 <bond.009@outlook.com>
This commit is contained in:
@@ -209,39 +209,69 @@ public class SkiaEncoder : IImageEncoder
|
|||||||
return default;
|
return default;
|
||||||
}
|
}
|
||||||
|
|
||||||
using var codec = SKCodec.Create(safePath, out var result);
|
SKCodec? codec = null;
|
||||||
|
bool isSafePathTemp = !string.Equals(Path.GetFullPath(safePath), Path.GetFullPath(path), StringComparison.OrdinalIgnoreCase);
|
||||||
switch (result)
|
try
|
||||||
{
|
{
|
||||||
case SKCodecResult.Success:
|
codec = SKCodec.Create(safePath, out var result);
|
||||||
// Skia/SkiaSharp edge‑case: when the image header is parsed but the actual pixel
|
switch (result)
|
||||||
// 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:
|
|
||||||
{
|
{
|
||||||
var boundsInfo = SKBitmap.DecodeBounds(safePath);
|
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);
|
||||||
|
|
||||||
if (boundsInfo.Width > 0 && boundsInfo.Height > 0)
|
case SKCodecResult.Unimplemented:
|
||||||
|
_logger.LogDebug("Image format not supported: {FilePath}", path);
|
||||||
|
return default;
|
||||||
|
|
||||||
|
default:
|
||||||
{
|
{
|
||||||
return new ImageDimensions(boundsInfo.Width, boundsInfo.Height);
|
var boundsInfo = SKBitmap.DecodeBounds(safePath);
|
||||||
}
|
if (boundsInfo.Width > 0 && boundsInfo.Height > 0)
|
||||||
|
{
|
||||||
|
return new ImageDimensions(boundsInfo.Width, boundsInfo.Height);
|
||||||
|
}
|
||||||
|
|
||||||
_logger.LogWarning(
|
_logger.LogWarning(
|
||||||
"Unable to determine image dimensions for {FilePath}: {SkCodecResult}",
|
"Unable to determine image dimensions for {FilePath}: {SkCodecResult}",
|
||||||
path,
|
path,
|
||||||
result);
|
result);
|
||||||
return default;
|
|
||||||
|
return default;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
finally
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
codec?.Dispose();
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
_logger.LogDebug(ex, "Error by closing codec for {FilePath}", safePath);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (isSafePathTemp)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
if (File.Exists(safePath))
|
||||||
|
{
|
||||||
|
File.Delete(safePath);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
_logger.LogDebug(ex, "Unable to remove temporary file '{TempPath}'", safePath);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user