{"record":{"id":"adb03bee828385bd","repo":"SixLabors/ImageSharp","slug":"the-ani-file-contains-an-unsupported-icon-resource","errorCode":null,"errorMessage":"The ANI file contains an unsupported icon resource.","messagePattern":"The ANI file contains an unsupported icon resource\\.","errorType":"exception","errorClass":"InvalidImageContentException","httpStatus":null,"severity":"error","filePath":"src/ImageSharp/Formats/Ani/AniDecoderCore.cs","lineNumber":672,"sourceCode":"    {\n        // Without AF_ICON, the icon chunk payload is a raw DIB and has no ICO/CUR directory prefix to inspect.\n        if (!this.header.Flags.HasFlag(AniHeaderFlags.IsIcon))\n        {\n            return AniFrameFormat.Bmp;\n        }\n\n        Span<byte> iconHeader = this.buffer[..AniConstants.IconDirHeaderSize];\n        if (stream.Read(iconHeader) != iconHeader.Length)\n        {\n            throw new InvalidImageContentException(\"The ANI file contains a truncated ICO or CUR resource.\");\n        }\n\n        IconFileType type = (IconFileType)BinaryPrimitives.ReadUInt16LittleEndian(iconHeader[2..]);\n        return type switch\n        {\n            IconFileType.ICO => AniFrameFormat.Ico,\n            IconFileType.CUR => AniFrameFormat.Cur,\n            _ => throw new InvalidImageContentException(\"The ANI file contains an unsupported icon resource.\")\n        };\n    }\n\n    /// <summary>\n    /// Decodes one embedded ANI frame resource.\n    /// </summary>\n    /// <typeparam name=\"TPixel\">The destination pixel type.</typeparam>\n    /// <param name=\"format\">The embedded resource format.</param>\n    /// <param name=\"options\">The nested decoder options.</param>\n    /// <param name=\"stream\">The bounded resource stream.</param>\n    /// <param name=\"cancellationToken\">The token to monitor for cancellation requests.</param>\n    /// <returns>The decoded resource.</returns>\n    private static Image<TPixel> DecodeFrame<TPixel>(AniFrameFormat format, DecoderOptions options, Stream stream, CancellationToken cancellationToken)\n        where TPixel : unmanaged, IPixel<TPixel>\n        => format switch\n        {\n            AniFrameFormat.Ico => new IcoDecoderCore(options).Decode<TPixel>(options.Configuration, stream, cancellationToken),\n            AniFrameFormat.Cur => new CurDecoderCore(options).Decode<TPixel>(options.Configuration, stream, cancellationToken),","sourceCodeStart":654,"sourceCodeEnd":690,"githubUrl":"https://github.com/SixLabors/ImageSharp/blob/59ce6af6fc29027cda277ef62d4d1694a8acce91/src/ImageSharp/Formats/Ani/AniDecoderCore.cs#L654-L690","documentation":"Thrown by AniDecoderCore when the 16-bit resource type field in an embedded icon directory header is neither ICO (1) nor CUR (2). The library only supports those two embedded resource types inside ANI files. Any other type value is treated as invalid content.","triggerScenarios":"Decoding an ANI file where an 'icon' chunk's ICONDIR wType field holds a value other than 1 (ICO) or 2 (CUR), such as 0 or 3+.","commonSituations":"Corrupted or hand-edited ANI files, files produced by non-conformant tools that write wrong resource types, fuzzed inputs.","solutions":["Rebuild the ANI with a compliant tool so embedded resources are ICO or CUR type.","Inspect the icon directory bytes at the chunk offset and fix the wType field to 1 or 2.","Catch InvalidImageContentException and reject the file."],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":"// Peek icon dir type: bytes at icon chunk payload offset +2, little-endian ushort; must be 1 (ICO) or 2 (CUR)\nushort type = BitConverter.ToUInt16(iconPayload, 2);\nbool ok = type is 1 or 2;","typeGuard":null,"tryCatchPattern":"try { var image = Image.Load(path); } catch (InvalidImageContentException ex) when (ex.Message.Contains(\"unsupported icon resource\")) { /* rebuild file */ }","preventionTips":["Only accept ANI files from tools known to embed ICO/CUR resources","Hex-inspect embedded icon headers when authoring ANI files","Pre-validate with Image.IdentifyAsync before decode"],"tags":["image-decoding","ani","ico","cur","unsupported-format"],"backgroundTag":"unsupported-enum-value","analyzedSha":"59ce6af6fc29027cda277ef62d4d1694a8acce91","analyzedAt":"2026-09-13T18:34:59.331Z","contentChangedAt":"2026-09-13T18:34:59.331Z","schemaVersion":2},"datasetVersion":"2026-09-16T04:17:20.429Z"}