{"record":{"id":"757cdef38ce80297","repo":"SixLabors/ImageSharp","slug":"bad-quantization-table-index-index","errorCode":null,"errorMessage":"Bad Quantization Table index {index}.","messagePattern":"Bad Quantization Table index (.+?)\\.","errorType":"exception","errorClass":"InvalidImageContentException","httpStatus":null,"severity":"error","filePath":"src/ImageSharp/Formats/Jpeg/JpegThrowHelper.cs","lineNumber":16,"sourceCode":"// Copyright (c) Six Labors.\n// Licensed under the Six Labors Split License.\n\nnamespace SixLabors.ImageSharp.Formats.Jpeg;\n\ninternal static class JpegThrowHelper\n{\n    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":1,"sourceCodeEnd":34,"githubUrl":"https://github.com/SixLabors/ImageSharp/blob/59ce6af6fc29027cda277ef62d4d1694a8acce91/src/ImageSharp/Formats/Jpeg/JpegThrowHelper.cs#L1-L34","documentation":"JpegThrowHelper.ThrowBadQuantizationTableIndex throws InvalidImageContentException when a DQT (define quantization table) segment references a table index outside the valid 0..3 range defined by the JPEG specification. The input stream's quantization table identifier is invalid.","triggerScenarios":"Decoding a JPEG whose DQT segment carries a quantization table ID (the parameter shown in the message) greater than 3 or otherwise malformed — corrupt streams or non-conformant encoders.","commonSituations":"Files produced by broken/embedded-device encoders; bit corruption in transit; fuzzed or malicious uploads to image-processing endpoints.","solutions":["Treat the file as corrupt: re-export or re-obtain it from the source.","Catch InvalidImageContentException in ingestion pipelines and reject/quarantine the file.","Re-encode the original image with a standards-compliant encoder to produce a valid DQT."],"exampleFix":"// before\nusing var image = Image.Load(untrustedStream);\n// after\ntry { using var image = Image.Load(untrustedStream); }\ncatch (InvalidImageContentException)\n{\n    reject(\"Invalid JPEG quantization table\");\n}","handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"try\n{\n    using var image = Image.Load(stream);\n}\ncatch (InvalidImageContentException ex) when (ex.Message.Contains(\"Quantization Table index\"))\n{\n    rejectUpload(\"Malformed JPEG quantization table\");\n}","preventionTips":["Validate image uploads at the edge (magic bytes, size, parse check) before processing.","Quarantine non-conformant files rather than crashing ingestion workers.","Re-export images from devices known to emit broken DQT segments."],"tags":["jpeg","decoder","corrupt-data","quantization-table"],"backgroundTag":"corrupt-jpeg-data","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"}