SubtitleEdit/subtitleedit · error · Exception

File type not supported

Error message

File type not supported

What it means

Thrown by Core.ScanByBufferAsync when SKCodec.Create throws while probing the buffer to detect the image format. The catch swallows the underlying SkiaSharp exception and rethrows a generic 'File type not supported' Exception, losing the original cause. It means the byte buffer is not a decodable image (PNG/JPEG/WEBP) that SkiaSharp recognizes.

Source

Thrown at src/ui/Logic/Ocr/GoogleLens/Core.cs:75

        return await ScanByBufferAsync(file);
    }

    public async Task<List<string>> ScanByBufferAsync(byte[] buffer)
    {
        SKEncodedImageFormat? format = null;
        
        try
        {
            using var stream = new MemoryStream(buffer);
            using var codec = SKCodec.Create(stream);
            if (codec != null)
            {
                format = codec.EncodedFormat;
            }
        }
        catch
        {
            throw new Exception("File type not supported");
        }

        var (Width, Height) = Helper.ImageDimensionsFromData(buffer);
        if (Width == 0 && Height == 0)
        {
            throw new Exception("Could not determine image dimensions");
        }

        // Google Lens does not accept images larger than 1000x1000
        if (Width > 1000 || Height > 1000)
        {
            buffer = await Helper.ResizeImageAsync(buffer, 1000, 1000);
        }

        string mimeType = format switch
        {
            SKEncodedImageFormat.Png => "image/png",
            SKEncodedImageFormat.Jpeg => "image/jpeg",

View on GitHub (pinned to 17a9f07487)

Solutions

  1. Validate the magic bytes (PNG/JPEG/WEBP signatures) before calling ScanByBufferAsync.
  2. Ensure the SkiaSharp native assets are installed for the target runtime.
  3. Convert unsupported formats (HEIC/TIFF) to PNG/JPEG upstream.
  4. Re-download or re-export the source image if it may be truncated.

Example fix

// before
var result = await core.ScanByBufferAsync(fileBytes);

// after
if (!IsRecognizedImage(fileBytes)) throw new ArgumentException("Provide a PNG/JPEG/WEBP image");
var result = await core.ScanByBufferAsync(fileBytes);
Defensive patterns

Strategy: validation

Validate before calling

static readonly byte[] Png = { 0x89,0x50,0x4E,0x47 };
static readonly byte[] Jpeg = { 0xFF,0xD8,0xFF };
static readonly byte[] Webp = { 0x52,0x49,0x46,0x46 }; // RIFF (check WEBP at offset 8)
static bool IsSupportedImage(byte[] b) =>
    b != null && b.Length >= 12 &&
    (b.Take(4).SequenceEqual(Png) || b.Take(3).SequenceEqual(Jpeg) ||
     (b.Take(4).SequenceEqual(Webp) && Encoding.ASCII.GetString(b,8,4) == "WEBP"));
if (!IsSupportedImage(buffer)) throw new ArgumentException("File type not supported");

Type guard

static bool IsRecognizedImage(byte[] b) => /* magic-byte check as above */ true;

Try / catch

try { var r = await core.ScanByBufferAsync(buffer); }
catch (Exception ex) when (ex.Message == "File type not supported") { /* notify user to pick PNG/JPEG/WEBP */ }

Prevention

When it happens

Trigger: Calling ScanByBufferAsync with a byte array that is not an image, is a corrupted/truncated image, or is in a format SkiaSharp cannot decode (e.g. TIFF, HEIC without native codec, BMP in some builds).

Common situations: User selected a non-image file for OCR; a partial download; a format not bundled in the platform's SkiaSharp native dependencies; an SVG or PDF mistaken for a raster image.

Related errors


AI-assisted analysis of SubtitleEdit/subtitleedit@17a9f07487 (2026-08-13). Data as JSON: /api/errors/3373dc216e1451a9. Report an issue: GitHub.