{"record":{"id":"a0d31b36779f0670","repo":"SixLabors/ImageSharp","slug":"not-enough-bytes-to-read-the-description","errorCode":null,"errorMessage":"Not enough bytes to read the {description}.","messagePattern":"Not enough bytes to read the (.+?)\\.","errorType":"exception","errorClass":"InvalidImageContentException","httpStatus":null,"severity":"error","filePath":"src/ImageSharp/Formats/Ani/AniDecoderCore.cs","lineNumber":852,"sourceCode":"        if (paddedEnd > containerEnd)\n        {\n            throw new InvalidImageContentException(\"An ANI RIFF chunk is missing its alignment padding.\");\n        }\n\n        return paddedEnd;\n    }\n\n    /// <summary>\n    /// Reads an exact number of bytes or reports a truncated ANI file.\n    /// </summary>\n    /// <param name=\"stream\">The ANI stream.</param>\n    /// <param name=\"destination\">The destination buffer.</param>\n    /// <param name=\"description\">The data description used in the error message.</param>\n    private static void ReadExactly(BufferedReadStream stream, Span<byte> destination, string description)\n    {\n        if (stream.Read(destination) != destination.Length)\n        {\n            throw new InvalidImageContentException($\"Not enough bytes to read the {description}.\");\n        }\n    }\n\n    /// <summary>\n    /// Converts a pixel dimension to the one-byte ICO/CUR representation.\n    /// </summary>\n    /// <param name=\"value\">The pixel dimension.</param>\n    /// <returns>The encoded dimension, where zero represents 256 pixels or greater.</returns>\n    private static byte NarrowDimension(int value) => value > byte.MaxValue ? (byte)0 : (byte)value;\n}\n","sourceCodeStart":834,"sourceCodeEnd":863,"githubUrl":"https://github.com/SixLabors/ImageSharp/blob/59ce6af6fc29027cda277ef62d4d1694a8acce91/src/ImageSharp/Formats/Ani/AniDecoderCore.cs#L834-L863","documentation":"Thrown by AniDecoderCore.ReadExactly when a bounded stream read returns fewer bytes than the destination span length. Used for all fixed-size ANI reads (headers, type fields, etc.); the {description} placeholder names what could not be read (e.g. 'RIFF list type', 'ANI header'). It signals the stream ended mid-structure.","triggerScenarios":"Decoding or identifying an ANI file where any fixed-size structure read (RIFF chunk headers, ANI header fields, icon directory entries) hits end-of-stream before the full span is filled.","commonSituations":"Truncated downloads, files cut off mid-header, corrupted ANI files, streams from network sources that ended prematurely.","solutions":["Re-obtain a complete ANI file; verify size against the source.","Check the stream source (file/network) is fully available and not cut off before decoding.","Catch InvalidImageContentException and surface the description from the message to pinpoint the missing structure."],"exampleFix":"// before\nvar image = Image.Load(stream);\n// after\nif (stream.CanSeek && stream.Length < 64) throw new InvalidDataException(\"ANI stream too short\");\nvar image = Image.Load(stream);","handlingStrategy":"try-catch","validationCode":"if (stream.CanSeek && stream.Length < 6) throw new InvalidDataException(\"Stream too short to be an ANI file.\");","typeGuard":null,"tryCatchPattern":"try { var image = await Image.LoadAsync(stream); } catch (InvalidImageContentException ex) { log.Error($\"Short read in ANI: {ex.Message}\"); }","preventionTips":["Check stream length/availability before decoding","Ensure downloads complete (Content-Length matches) before decoding","Buffer network streams fully before handing them to the decoder"],"tags":["image-decoding","ani","truncated-stream","short-read"],"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"}