{"record":{"id":"6aedcd026ae07a65","repo":"SixLabors/ImageSharp","slug":"invalid-bmp-icc-profile","errorCode":null,"errorMessage":"Invalid BMP ICC profile.","messagePattern":"Invalid BMP ICC profile\\.","errorType":"exception","errorClass":"InvalidIccProfileException","httpStatus":null,"severity":"error","filePath":"src/ImageSharp/Formats/Bmp/BmpDecoderCore.cs","lineNumber":1500,"sourceCode":"            BmpThrowHelper.ThrowInvalidImageContentException(\"Not enough data to read BMP ICC profile.\");\n        }\n\n        byte[] iccProfileData = new byte[this.infoHeader.ProfileSize];\n        stream.Position = profileStart;\n\n        if (stream.Read(iccProfileData) != iccProfileData.Length)\n        {\n            BmpThrowHelper.ThrowInvalidImageContentException(\"Not enough data to read BMP ICC profile.\");\n        }\n\n        IccProfile profile = new(iccProfileData);\n        if (profile.CheckIsValid())\n        {\n            imageMetadata.IccProfile = profile;\n        }\n        else\n        {\n            throw new InvalidIccProfileException(\"Invalid BMP ICC profile.\");\n        }\n    }\n\n    /// <summary>\n    /// Reads the <see cref=\"BmpFileHeader\"/> from the stream.\n    /// </summary>\n    /// <param name=\"stream\">The <see cref=\"BufferedReadStream\"/> containing image data.</param>\n    private void ReadFileHeader(BufferedReadStream stream)\n    {\n        Span<byte> buffer = stackalloc byte[BmpFileHeader.Size];\n        stream.Read(buffer, 0, BmpFileHeader.Size);\n\n        short fileTypeMarker = BinaryPrimitives.ReadInt16LittleEndian(buffer);\n        switch (fileTypeMarker)\n        {\n            case BmpConstants.TypeMarkers.Bitmap:\n                this.fileMarkerType = BmpFileMarkerType.Bitmap;\n                this.fileHeader = BmpFileHeader.Parse(buffer);","sourceCodeStart":1482,"sourceCodeEnd":1518,"githubUrl":"https://github.com/SixLabors/ImageSharp/blob/59ce6af6fc29027cda277ef62d4d1694a8acce91/src/ImageSharp/Formats/Bmp/BmpDecoderCore.cs#L1482-L1518","documentation":"When a BMP V5 header carries an embedded ICC profile, the decoder parses it and validates it with CheckIsValid(). If the profile bytes fail validation, it throws InvalidIccProfileException instead of attaching an invalid profile to the image metadata.","triggerScenarios":"Decoding a BMP with a V5 header whose profileData/profileSize point at bytes that do not form a valid ICC profile (truncated profile, wrong offset, garbage bytes).","commonSituations":"BMPs written by tools that embed malformed or proprietary color profiles; files edited/truncated after export so the profile region is damaged.","solutions":["Re-export the BMP without an embedded ICC profile (V4/V3 header) or with a valid sRGB profile.","Strip or fix the profile data region in the file.","Catch InvalidIccProfileException and decode via a lower-level path or reject the file."],"exampleFix":"// before\nusing Image img = Image.Load(bmpBytes); // throws on bad ICC\n// after\ntry { using Image img = Image.Load(bmpBytes); }\ncatch (InvalidIccProfileException) { /* handle file without color management */ }","handlingStrategy":"try-catch","validationCode":"// no cheap pre-check available; validate after failure by decoding with a V3/V4-header copy of the file","typeGuard":null,"tryCatchPattern":"try { using var img = Image.Load(bmpStream); }\ncatch (InvalidIccProfileException) { bmpStream.Seek(0, SeekOrigin.Begin); /* decode ignoring color profile or reject */ }","preventionTips":["Export BMPs without embedded ICC profiles when consumers don't need them.","Avoid round-tripping BMPs through lossy/truncating editors.","Validate embedded profiles at ingest time."],"tags":["bmp","icc-profile","decoding","color-management"],"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"}