SixLabors/ImageSharp · error · InvalidImageContentException
Unknown Quantization Table precision
Error message
Unknown Quantization Table precision {precision}. What it means
JpegThrowHelper.ThrowBadQuantizationTablePrecision throws InvalidImageContentException when a DQT segment declares a quantization table precision (the value in the message, encoded in the upper nibble of the table's first byte) other than the supported values — the JPEG spec allows 0 (8-bit) and, for 16-bit tables, 1; anything else is invalid.
Solutions
- Treat the input as corrupt and re-obtain/re-export the image.
- Catch InvalidImageContentException and reject the file in ingestion paths.
- Verify the producing encoder conforms to ITU T.81; re-encode with a standard library if not.
Example fix
// before
using var image = Image.Load(stream);
// after
try { using var image = Image.Load(stream); }
catch (InvalidImageContentException ex)
{
logger.LogWarning(ex, "Bad DQT precision");
} Defensive patterns
Strategy: try-catch
Try / catch
try
{
using var image = Image.Load(stream);
}
catch (InvalidImageContentException ex) when (ex.Message.Contains("Quantization Table precision"))
{
rejectUpload("Unsupported DQT precision");
} Prevention
- For untrusted uploads, decode in an isolated step and reject on InvalidImageContentException.
- Re-encode source images with a standards-compliant encoder before storage.
- Log the offending file for corpus analysis if corruption rates rise.
When it happens
Trigger: Decoding a JPEG whose DQT precision nibble is not 0 or 1 — corrupt streams, hand-crafted/fuzzed data, or output from a non-conformant encoder.
Common situations: Malformed files from buggy embedded encoders; corrupted transfers; adversarial uploads to public image endpoints.
Related errors
- Bad Quantization Table index
- Marker has bad length .
- Bad sampling factor.
- {errorMessage}
- Input stream does not have enough bytes to parse declared…
AI-assisted analysis of SixLabors/ImageSharp@59ce6af6fc (2026-09-13).
Data as JSON: /api/errors/8288b895e697678c.
Report an issue: GitHub.
Appendix: source
Thrown at src/ImageSharp/Formats/Jpeg/JpegThrowHelper.cs:18
// Copyright (c) Six Labors.
// Licensed under the Six Labors Split License.
namespace SixLabors.ImageSharp.Formats.Jpeg;
internal static class JpegThrowHelper
{
public static void ThrowNotSupportedException(string errorMessage) => throw new NotSupportedException(errorMessage);
public static void ThrowInvalidImageContentException(string errorMessage) => throw new InvalidImageContentException(errorMessage);
public static void ThrowBadMarker(string marker, int length) => throw new InvalidImageContentException($"Marker {marker} has bad length {length}.");
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.");
public static void ThrowBadQuantizationTableIndex(int index) => throw new InvalidImageContentException($"Bad Quantization Table index {index}.");
public static void ThrowBadQuantizationTablePrecision(int precision) => throw new InvalidImageContentException($"Unknown Quantization Table precision {precision}.");
public static void ThrowBadSampling() => throw new InvalidImageContentException("Bad sampling factor.");
public static void ThrowBadSampling(int factor) => throw new InvalidImageContentException($"Bad sampling factor: {factor}");
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}.");
public static void ThrowInvalidImageDimensions(int width, int height) => throw new InvalidImageContentException($"Invalid image dimensions: {width}x{height}.");
public static void ThrowDimensionsTooLarge(int width, int height) => throw new ImageFormatException($"Image is too large to encode at {width}x{height} for JPEG format.");
public static void ThrowNotSupportedComponentCount(int componentCount) => throw new NotSupportedException($"Images with {componentCount} components are not supported.");
public static void ThrowNotSupportedColorSpace() => throw new NotSupportedException("Image color space could not be deduced.");
}
View on GitHub (pinned to 59ce6af6fc)