{"record":{"id":"5356dcd54b15d8e6","repo":"SixLabors/ImageSharp","slug":"invalid-icc-profile-webpchunkparsingutils","errorCode":null,"errorMessage":"Invalid ICC profile.","messagePattern":"Invalid ICC profile\\.","errorType":"exception","errorClass":"InvalidIccProfileException","httpStatus":null,"severity":"error","filePath":"src/ImageSharp/Formats/Webp/WebpChunkParsingUtils.cs","lineNumber":397,"sourceCode":"    {\n        ulong chunkSize = ReadPaddedChunkSize(stream, stackalloc byte[4], true);\n\n        // ICCP precedes image/frame data. Its framing must be readable even when\n        // metadata is skipped; otherwise there is no safe location to resume decoding.\n        if (!stream.IsReadRangeValid(stream.Position, chunkSize))\n        {\n            WebpThrowHelper.ThrowInvalidImageContentException(\"Not enough data to read the ICCP chunk.\");\n        }\n\n        executeAncillarySegmentAction(() =>\n        {\n            byte[]? iccpData = ReadMetadataChunk(stream, chunkSize, ignoreMetadata || metadata.IccProfile != null);\n            if (iccpData is not null)\n            {\n                IccProfile profile = new(iccpData);\n                if (!profile.CheckIsValid())\n                {\n                    throw new InvalidIccProfileException(\"Invalid ICC profile.\");\n                }\n\n                metadata.IccProfile = profile;\n            }\n        });\n    }\n\n    /// <summary>\n    /// Reads the EXIF profile from the stream.\n    /// </summary>\n    /// <param name=\"stream\">The stream to decode from.</param>\n    /// <param name=\"metadata\">The image metadata.</param>\n    /// <param name=\"ignoreMetadata\">If true, metadata will be ignored.</param>\n    public static void ReadExifProfile(\n        BufferedReadStream stream,\n        ImageMetadata metadata,\n        bool ignoreMetadata)\n    {","sourceCodeStart":379,"sourceCodeEnd":415,"githubUrl":"https://github.com/SixLabors/ImageSharp/blob/59ce6af6fc29027cda277ef62d4d1694a8acce91/src/ImageSharp/Formats/Webp/WebpChunkParsingUtils.cs#L379-L415","documentation":"WebpChunkParsingUtils.ReadIccProfile throws InvalidIccProfileException when an ICCP chunk is present but the embedded ICC profile fails IccProfile.CheckIsValid(). The profile bytes were read fine, but they do not form a structurally valid ICC profile, so the decoder refuses to attach it to the image metadata.","triggerScenarios":"Decoding a WebP whose ICCP chunk contains malformed or non-ICC data — profile header size/signature checks fail inside CheckIsValid, typically while metadata is being loaded (ignoreMetadata=false and no existing profile).","commonSituations":"Files produced by encoders that wrote garbage or truncated color profiles; hand-assembled ICCP chunks; profiles stripped/converted by middleware; exotic color-management pipelines.","solutions":["Strip or repair the ICC profile: re-encode the file without ICCP (e.g. cwebp -no-icc or re-save with a valid profile).","Assign a known-good ICC profile after decoding instead of relying on the embedded one.","Catch InvalidIccProfileException and fall back to decoding while ignoring metadata.","Verify the profile with a validator (e.g. ICC profile inspection tools) to confirm corruption."],"exampleFix":"// before\nusing var image = Image.Load(stream); // throws on bad ICCP\n// after\nvar dec = new WebpDecoder(); // or:\ntry { using var image = Image.Load(stream); }\ncatch (InvalidIccProfileException) { /* decode with metadata ignored or re-source the file */ }","handlingStrategy":"fallback","validationCode":null,"typeGuard":null,"tryCatchPattern":"try { using var image = Image.Load(stream); return image; }\ncatch (InvalidIccProfileException) { /* retry ignoring metadata / re-encode without ICCP */ return DecodeIgnoringMetadata(stream); }","preventionTips":["Re-encode sources with cwebp -no-icc when ICCP validity is uncertain","Keep a known-good default ICC profile to apply after decode","Catch InvalidIccProfileException separately from ImageFormatException"],"tags":["webp","icc-profile","validation","metadata"],"backgroundTag":"schema-validation-failed","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"}