{"record":{"id":"ce4fb4d2f62deb33","repo":"SixLabors/ImageSharp","slug":"png-image-does-not-contain-a-palette-chunk","errorCode":null,"errorMessage":"PNG Image does not contain a palette chunk.","messagePattern":"PNG Image does not contain a palette chunk\\.","errorType":"exception","errorClass":"InvalidImageContentException","httpStatus":null,"severity":"error","filePath":"src/ImageSharp/Formats/Png/PngThrowHelper.cs","lineNumber":30,"sourceCode":"    public static void ThrowInvalidImageContentException(string errorMessage) => throw new InvalidImageContentException(errorMessage);\n\n    [DoesNotReturn]\n    public static void ThrowInvalidHeader() => throw new InvalidImageContentException(\"PNG Image must contain a header chunk and it must be located before any other chunks.\");\n\n    [DoesNotReturn]\n    public static void ThrowNoData() => throw new InvalidImageContentException(\"PNG Image does not contain a data chunk.\");\n\n    [DoesNotReturn]\n    public static void ThrowMissingDefaultData() => throw new InvalidImageContentException(\"APNG Image does not contain a default data chunk.\");\n\n    [DoesNotReturn]\n    public static void ThrowInvalidAnimationControl() => throw new InvalidImageContentException(\"APNG Image must contain a acTL chunk and it must be located before any IDAT and fdAT chunks.\");\n\n    [DoesNotReturn]\n    public static void ThrowMissingFrameControl() => throw new InvalidImageContentException(\"One of APNG Image's frames do not have a frame control chunk.\");\n\n    [DoesNotReturn]\n    public static void ThrowMissingPalette() => throw new InvalidImageContentException(\"PNG Image does not contain a palette chunk.\");\n\n    [DoesNotReturn]\n    public static void ThrowInvalidChunkType() => throw new InvalidImageContentException(\"Invalid PNG data.\");\n\n    [DoesNotReturn]\n    public static void ThrowInvalidChunkType(string message) => throw new InvalidImageContentException(message);\n\n    [DoesNotReturn]\n    public static void ThrowInvalidChunkCrc(string chunkTypeName) => throw new InvalidImageContentException($\"CRC Error. PNG {chunkTypeName} chunk is corrupt!\");\n\n    [DoesNotReturn]\n    public static void ThrowInvalidParameter(object value, string message, [CallerArgumentExpression(nameof(value))] string name = \"\")\n        => throw new NotSupportedException($\"Invalid {name}. {message}. Was '{value}'.\");\n\n    [DoesNotReturn]\n    public static void ThrowInvalidParameter(object value1, object value2, string message, [CallerArgumentExpression(nameof(value1))] string name1 = \"\", [CallerArgumentExpression(nameof(value2))] string name2 = \"\")\n        => throw new NotSupportedException($\"Invalid {name1} or {name2}. {message}. Was '{value1}' and '{value2}'.\");\n","sourceCodeStart":12,"sourceCodeEnd":48,"githubUrl":"https://github.com/SixLabors/ImageSharp/blob/59ce6af6fc29027cda277ef62d4d1694a8acce91/src/ImageSharp/Formats/Png/PngThrowHelper.cs#L12-L48","documentation":"Thrown when decoding an indexed-color (palette-based) PNG whose PLTE (palette) chunk is absent. Palette and grayscale+palette color types are defined by their palette; without PLTE the pixel indices cannot be mapped to colors, so the decode is invalid.","triggerScenarios":"Decoding a PNG with color type 3 (indexed) that contains no PLTE chunk before the IDAT data; truncated files that lost the PLTE; files mislabeled with an indexed color type.","commonSituations":"Bit-reduced or quantized images saved by buggy tools without the palette, files edited to change the color type but not add a palette, truncated downloads.","solutions":["Re-export the image ensuring a PLTE chunk is written for indexed color type 3.","Re-save as RGB/RGBA (non-palette) if a palette is not required.","Check the file wasn't truncated between IHDR and PLTE.","Catch InvalidImageContentException and reject the input."],"exampleFix":"// before (encoder)\nWriteChunk(ihdr with colorType=Indexed); WriteChunk(idat);\n// after\nWriteChunk(ihdr with colorType=Indexed); WriteChunk(plte); WriteChunk(idat);","handlingStrategy":"validation","validationCode":"// For indexed PNGs (color type 3), confirm a PLTE chunk exists before IDAT by scanning chunk headers\nstatic bool HasPlte(ReadOnlySpan<byte> png) { /* walk chunks: len, type, data, crc */ return foundPlte; }","typeGuard":null,"tryCatchPattern":"try\n{\n    using var image = Image.Load(stream);\n}\ncatch (InvalidImageContentException ex) when (ex.Message.Contains(\"palette\"))\n{\n    // indexed PNG without PLTE — reject or re-encode as RGBA\n}","preventionTips":["When encoding indexed PNGs, always emit PLTE before IDAT.","If you change a PNG's color type, update/add the palette accordingly.","Prefer saving as RGBA when palette handling is not required."],"tags":["png","plte","palette","indexed-color"],"backgroundTag":"invalid-image-content","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"}