{"record":{"id":"4d0854ef4c527d90","repo":"SixLabors/ImageSharp","slug":"the-ani-file-contains-a-truncated-riff-list","errorCode":null,"errorMessage":"The ANI file contains a truncated RIFF list.","messagePattern":"The ANI file contains a truncated RIFF list\\.","errorType":"exception","errorClass":"InvalidImageContentException","httpStatus":null,"severity":"error","filePath":"src/ImageSharp/Formats/Ani/AniDecoderCore.cs","lineNumber":335,"sourceCode":"\n        this.aniMetadata.Width = this.header.Width;\n        this.aniMetadata.Height = this.header.Height;\n        this.aniMetadata.BitCount = this.header.BitCount;\n        this.aniMetadata.Planes = this.header.Planes;\n        this.aniMetadata.DisplayRate = this.header.DisplayRate;\n        this.aniMetadata.Flags = this.header.Flags;\n    }\n\n    /// <summary>\n    /// Reads a RIFF list type and records or parses its contents.\n    /// </summary>\n    /// <param name=\"stream\">The ANI stream.</param>\n    /// <param name=\"listEnd\">The exclusive end of the list payload.</param>\n    private void ReadList(BufferedReadStream stream, long listEnd)\n    {\n        if (listEnd - stream.Position < sizeof(uint))\n        {\n            throw new InvalidImageContentException(\"The ANI file contains a truncated RIFF list.\");\n        }\n\n        Span<byte> typeData = this.buffer[..sizeof(uint)];\n        ReadExactly(stream, typeData, \"RIFF list type\");\n        AniListType type = (AniListType)BinaryPrimitives.ReadUInt32LittleEndian(typeData);\n\n        switch (type)\n        {\n            case AniListType.Frames:\n                // Defer nested decoding until the complete container has supplied any later seq/rate chunks.\n                this.frameLists.Add((stream.Position, listEnd));\n                break;\n            case AniListType.Info when !this.Options.SkipMetadata:\n                this.ExecuteAncillarySegmentAction(() => this.ReadInfoList(stream, listEnd));\n                break;\n        }\n    }\n","sourceCodeStart":317,"sourceCodeEnd":353,"githubUrl":"https://github.com/SixLabors/ImageSharp/blob/59ce6af6fc29027cda277ef62d4d1694a8acce91/src/ImageSharp/Formats/Ani/AniDecoderCore.cs#L317-L353","documentation":"Thrown by AniDecoderCore.ReadList when the remaining bytes between the current stream position and the declared list end are fewer than 4 bytes, so the RIFF list type field cannot be read. The library treats this as corrupt content rather than guessing. It indicates the ANI file declares a RIFF list whose payload is shorter than its declared structure.","triggerScenarios":"Decoding an ANI file via Image.LoadAsync/Image.IdentifyAsync where a RIFF list (RIFF/ 'acon' or 'fram') payload ends fewer than 4 bytes after the list header, i.e. a truncated list type field.","commonSituations":"Partially downloaded ANI files, files truncated by transfer tools, hand-crafted or fuzzed ANI files with incorrect list sizes in the RIFF chunk headers.","solutions":["Re-obtain the ANI file from a trusted source and verify it is complete (compare file size/checksum).","Validate the RIFF chunk sizes with a hex editor or riff inspection tool before decoding.","Catch InvalidImageContentException and reject the file as corrupt instead of attempting decode."],"exampleFix":"// before\nvar image = Image.Load(\"broken.ani\");\n// after\ntry { var image = Image.Load(\"broken.ani\"); }\ncatch (InvalidImageContentException ex) { Console.WriteLine($\"Corrupt ANI: {ex.Message}\"); }","handlingStrategy":"try-catch","validationCode":"static bool IsPlausibleAni(byte[] bytes) => bytes.Length >= 12 && bytes.AsSpan(0, 4).SequenceEqual(\"RIFF\"u8) && bytes.AsSpan(8, 4).SequenceEqual(\"ACON\"u8) && bytes.Length >= BitConverter.ToUInt32(bytes, 4) + 8;","typeGuard":null,"tryCatchPattern":"try { var image = Image.Load(path); } catch (InvalidImageContentException ex) { log.Warn($\"Corrupt ANI rejected: {ex.Message}\"); }","preventionTips":["Verify file completeness (size/checksum) before decoding untrusted ANI files","Use Image.Identify as a cheap pre-check before full decode","Validate RIFF chunk hierarchy with an inspector tool for hand-crafted files"],"tags":["image-decoding","ani","riff","truncated-file","invalid-image-content"],"backgroundTag":"invalid-argument-format","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"}