{"record":{"id":"41c488ceb89bd00e","repo":"SixLabors/ImageSharp","slug":"invalid-image-dimensions-width-x-height","errorCode":null,"errorMessage":"Invalid image dimensions: {width}x{height}.","messagePattern":"Invalid image dimensions: (.+?)x(.+?)\\.","errorType":"exception","errorClass":"InvalidImageContentException","httpStatus":null,"severity":"error","filePath":"src/ImageSharp/Formats/Jpeg/JpegThrowHelper.cs","lineNumber":26,"sourceCode":"    public static void ThrowNotSupportedException(string errorMessage) => throw new NotSupportedException(errorMessage);\n\n    public static void ThrowInvalidImageContentException(string errorMessage) => throw new InvalidImageContentException(errorMessage);\n\n    public static void ThrowBadMarker(string marker, int length) => throw new InvalidImageContentException($\"Marker {marker} has bad length {length}.\");\n\n    public static void ThrowNotEnoughBytesForMarker(byte marker) => throw new InvalidImageContentException($\"Input stream does not have enough bytes to parse declared contents of the {marker:X2} marker.\");\n\n    public static void ThrowBadQuantizationTableIndex(int index) => throw new InvalidImageContentException($\"Bad Quantization Table index {index}.\");\n\n    public static void ThrowBadQuantizationTablePrecision(int precision) => throw new InvalidImageContentException($\"Unknown Quantization Table precision {precision}.\");\n\n    public static void ThrowBadSampling() => throw new InvalidImageContentException(\"Bad sampling factor.\");\n\n    public static void ThrowBadSampling(int factor) => throw new InvalidImageContentException($\"Bad sampling factor: {factor}\");\n\n    public static void ThrowBadProgressiveScan(int ss, int se, int ah, int al) => throw new InvalidImageContentException($\"Invalid progressive parameters Ss={ss} Se={se} Ah={ah} Al={al}.\");\n\n    public static void ThrowInvalidImageDimensions(int width, int height) => throw new InvalidImageContentException($\"Invalid image dimensions: {width}x{height}.\");\n\n    public static void ThrowDimensionsTooLarge(int width, int height) => throw new ImageFormatException($\"Image is too large to encode at {width}x{height} for JPEG format.\");\n\n    public static void ThrowNotSupportedComponentCount(int componentCount) => throw new NotSupportedException($\"Images with {componentCount} components are not supported.\");\n\n    public static void ThrowNotSupportedColorSpace() => throw new NotSupportedException(\"Image color space could not be deduced.\");\n}\n","sourceCodeStart":8,"sourceCodeEnd":34,"githubUrl":"https://github.com/SixLabors/ImageSharp/blob/59ce6af6fc29027cda277ef62d4d1694a8acce91/src/ImageSharp/Formats/Jpeg/JpegThrowHelper.cs#L8-L34","documentation":"JpegThrowHelper.ThrowInvalidImageDimensions(width, height) throws InvalidImageContentException when the dimensions parsed from a JPEG SOF (frame header) marker are invalid, e.g. zero, negative after ushort decode semantics, or otherwise impossible for the decoder to allocate. It flags corrupt or non-conformant JPEG content, not a caller bug.","triggerScenarios":"Decoding a JPEG whose SOF marker contains width or height of 0; a corrupted/truncated SOF segment; a non-JPEG file whose bytes happen to be parsed until a bogus SOF is found via Image.Load or Image.Identify.","commonSituations":"Zero-byte-truncated downloads that still parse partially; files damaged by text-mode transfers; deliberately crafted fuzz inputs; mixups where a non-image file is handed to the loader.","solutions":["Verify the input is an intact JPEG (starts with FFD8, plausible SOF) before decoding; re-obtain the file if corrupt.","Catch InvalidImageContentException around load/identify calls and skip or report the file.","If dimensions matter for your pipeline, pre-validate with Image.Identify and check IImageInfo dimensions before full decode."],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"// try\n{\n    using Image image = Image.Load(stream);\n}\ncatch (InvalidImageContentException ex)\n{\n    logger.LogWarning(ex, \"Invalid JPEG dimensions, skipping file\");\n}","preventionTips":["Check the file starts with the JPEG SOI marker (FF D8) before decoding.","Verify downloaded files are complete (checksums, content-length) before processing.","Use Image.Identify to obtain dimensions safely before full decode."],"tags":["jpeg","decoding","corrupt-data","image-dimensions"],"backgroundTag":"value-out-of-range","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"}