{"record":{"id":"1fc821496f6b9a1f","repo":"SixLabors/ImageSharp","slug":"icc-conversion-supports-at-most-four-input-and-output","errorCode":null,"errorMessage":"ICC conversion supports at most four input and output channels.","messagePattern":"ICC conversion supports at most four input and output channels\\.","errorType":"exception","errorClass":"InvalidIccProfileException","httpStatus":null,"severity":"error","filePath":"src/ImageSharp/ColorProfiles/Icc/Calculators/ClutCalculator.cs","lineNumber":47,"sourceCode":"    private readonly uint[] nPower;\n    private int n000;\n    private int n001;\n    private int n010;\n    private int n011;\n    private int n100;\n    private int n101;\n    private int n110;\n    private int n111;\n    private int n1000;\n\n    public ClutCalculator(IccClut clut)\n    {\n        Guard.NotNull(clut, nameof(clut));\n        Guard.MustBeGreaterThan(clut.InputChannelCount, 0, nameof(clut.InputChannelCount));\n        Guard.MustBeGreaterThan(clut.OutputChannelCount, 0, nameof(clut.OutputChannelCount));\n        if (clut.InputChannelCount > 4 || clut.OutputChannelCount > 4)\n        {\n            throw new InvalidIccProfileException(\"ICC conversion supports at most four input and output channels.\");\n        }\n\n        this.inputCount = clut.InputChannelCount;\n        this.outputCount = clut.OutputChannelCount;\n        this.g = new float[this.inputCount];\n        this.ig = new uint[this.inputCount];\n        this.s = new float[this.inputCount];\n        this.nPower = new uint[16];\n        this.lut = clut.Values;\n        this.nodeCount = (int)Math.Pow(2, clut.InputChannelCount);\n        this.df = new float[this.nodeCount];\n        this.nodes = new float[this.nodeCount][];\n        this.dimSize = new int[this.inputCount];\n        this.gridPointCount = clut.GridPointCount;\n        this.maxGridPoint = new byte[this.inputCount];\n        for (int i = 0; i < this.inputCount; i++)\n        {\n            this.maxGridPoint[i] = (byte)(this.gridPointCount[i] - 1);","sourceCodeStart":29,"sourceCodeEnd":65,"githubUrl":"https://github.com/SixLabors/ImageSharp/blob/59ce6af6fc29027cda277ef62d4d1694a8acce91/src/ImageSharp/ColorProfiles/Icc/Calculators/ClutCalculator.cs#L29-L65","documentation":"ClutCalculator's constructor rejects ICC CLUT (color lookup table) entries with more than 4 input or output channels by throwing InvalidIccProfileException. The calculator's internal Vector4-based processing only supports up to four channels per side, as used by ICC device spaces like RGB and CMYK.","triggerScenarios":"Constructing a ClutCalculator (directly or via LutEntryCalculator) from an IccClut whose InputChannelCount or OutputChannelCount exceeds 4 — typically a malformed or hand-crafted ICC profile with more device channels than any supported space.","commonSituations":"Loading a corrupt or non-standard ICC profile from the wild; profiles edited or truncated by third-party tools; profiles for exotic N-channel device spaces beyond CMYK.","solutions":["Replace the ICC profile with one from a trusted source / re-exported from a standard tool (Photoshop, littleCMS).","Validate the profile's CLUT channel counts before conversion and reject profiles with >4 channels.","If N-channel support is genuinely needed, it is unsupported by this converter; pre-convert the image with an external ICC engine."],"exampleFix":"// before\nvar calc = new ClutCalculator(profile.Clut); // may throw\n// after\nif (profile.Clut.InputChannelCount > 4 || profile.Clut.OutputChannelCount > 4)\n{\n    throw new NotSupportedException(\"Profile uses more than 4 CLUT channels.\");\n}\nvar calc = new ClutCalculator(profile.Clut);","handlingStrategy":"validation","validationCode":"if (clut.InputChannelCount > 4 || clut.OutputChannelCount > 4)\n{\n    throw new NotSupportedException(\"ICC profile CLUT exceeds 4 channels; unsupported.\");\n}","typeGuard":null,"tryCatchPattern":"try { converter.Convert(...); }\ncatch (InvalidIccProfileException ex) { logger.LogWarning(ex, \"Profile has unsupported CLUT channel counts\"); /* fall back to sRGB assumption */ }","preventionTips":["Only accept ICC profiles from trusted sources / re-export with standard tools.","Validate CLUT channel counts during profile intake.","Treat N-channel (>CMYK) profiles as unsupported and route them to an external ICC engine."],"tags":["icc","color-management","profile-validation","csharp"],"backgroundTag":"invalid-argument-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"}