{"record":{"id":"f2547f074c922b64","repo":"SixLabors/ImageSharp","slug":"message","errorCode":null,"errorMessage":"{message}","messagePattern":"\\{message\\}","errorType":"exception","errorClass":"InvalidImageContentException","httpStatus":null,"severity":"error","filePath":"src/ImageSharp/Formats/ImageDecoderCore.cs","lineNumber":100,"sourceCode":"            or InvalidImageContentException\n            or InvalidOperationException\n            or NotSupportedException)\n        {\n            // Intentionally ignored when image data integrity handling is set to IgnoreImageData.\n        }\n    }\n\n    /// <summary>\n    /// Throws unless the decoder is running in a non-strict segment integrity mode.\n    /// Use this only from within <see cref=\"ExecuteAncillarySegmentAction\"/> when local control flow\n    /// must continue after the error.\n    /// </summary>\n    /// <param name=\"message\">The exception message.</param>\n    protected void ThrowOrIgnoreNonStrictSegmentError(string message)\n    {\n        if (this.Options.SegmentIntegrityHandling is SegmentIntegrityHandling.Strict)\n        {\n            throw new InvalidImageContentException(message);\n        }\n    }\n\n    /// <summary>\n    /// Reads the raw image information from the specified stream.\n    /// </summary>\n    /// <param name=\"configuration\">The shared configuration.</param>\n    /// <param name=\"stream\">The <see cref=\"Stream\" /> containing image data.</param>\n    /// <param name=\"cancellationToken\">The token to monitor for cancellation requests.</param>\n    /// <returns>The <see cref=\"ImageInfo\" />.</returns>\n    /// <exception cref=\"InvalidImageContentException\">Thrown if the encoded image contains errors.</exception>\n    public ImageInfo Identify(\n        Configuration configuration,\n        Stream stream,\n        CancellationToken cancellationToken)\n    {\n        using BufferedReadStream bufferedReadStream = new(configuration, stream, cancellationToken);\n","sourceCodeStart":82,"sourceCodeEnd":118,"githubUrl":"https://github.com/SixLabors/ImageSharp/blob/59ce6af6fc29027cda277ef62d4d1694a8acce91/src/ImageSharp/Formats/ImageDecoderCore.cs#L82-L118","documentation":"ImageDecoderCore.ThrowOrIgnoreNonStrictSegmentError converts malformed-segment reports into InvalidImageContentException when Options.SegmentIntegrityHandling is Strict. In non-strict modes the corrupt segment is tolerated and decoding continues, so this exception only surfaces for data that is structurally corrupt in a segment the caller asked to be strict about.","triggerScenarios":"Decoding/Identifying an image with a corrupted or non-conformant segment (e.g. truncated JPEG markers, bad chunk data) while options.SegmentIntegrityHandling == SegmentIntegrityHandling.Strict (the default on ImageDecoder options).","commonSituations":"Partially downloaded or truncated image files; images damaged by resaving/transcoding tools; deliberately fuzzed or malicious files; servers returning HTML error pages with image content types.","solutions":["Set options.SegmentIntegrityHandling to SegmentIntegrityHandling.Ignore or DecodeMissingSegments/looser mode if tolerant decoding is acceptable","Catch InvalidImageContentException and fall back to a placeholder image or error handling","Repair or re-obtain the source file, verifying integrity (checksum, complete download)","Validate the file is actually an image of the claimed format before decoding"],"exampleFix":"// before\nvar image = Image.Load(file); // InvalidImageContentException on corrupt segment\n// after\nvar opts = new DecoderOptions { SegmentIntegrityHandling = SegmentIntegrityHandling.Ignore };\nvar image = Image.Load(opts, file);","handlingStrategy":"try-catch","validationCode":"if (!HasKnownImageMagicBytes(bytes)) throw new InvalidOperationException(\"Not a recognized image file.\");","typeGuard":null,"tryCatchPattern":"try { var image = Image.Load(opts, stream); }\ncatch (InvalidImageContentException ex)\n{\n    // strict segment handling rejected a corrupt segment\n    logger.LogWarning(ex, \"Corrupt image segment\");\n}","preventionTips":["Verify downloads complete (content-length / checksum) before decoding","Choose SegmentIntegrityHandling deliberately per use case","Quarantine files that throw instead of retrying the same bytes"],"tags":["dotnet","image-decoding","corrupt-data","strict-mode"],"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"}