{"record":{"id":"09616408ba902172","repo":"SixLabors/ImageSharp","slug":"progressive-scans-must-be-in-2-64-range","errorCode":null,"errorMessage":"Progressive scans must be in [2..64] range.","messagePattern":"Progressive scans must be in \\[2\\.\\.64\\] range\\.","errorType":"validation","errorClass":"ArgumentException","httpStatus":null,"severity":"error","filePath":"src/ImageSharp/Formats/Jpeg/JpegEncoder.cs","lineNumber":67,"sourceCode":"    public bool Progressive { get; init; }\n\n    /// <summary>\n    /// Gets number of scans per component for progressive encoding.\n    /// Defaults to <value>4</value>.\n    /// </summary>\n    /// <remarks>\n    /// Number of scans must be between 2 and 64.\n    /// There is at least one scan for the DC coefficients and one for the remaining 63 AC coefficients.\n    /// </remarks>\n    /// <exception cref=\"ArgumentException\">Progressive scans must be in [2..64] range.</exception>\n    public int ProgressiveScans\n    {\n        get => this.progressiveScans;\n        init\n        {\n            if (value is < 2 or > 64)\n            {\n                throw new ArgumentException(\"Progressive scans must be in [2..64] range.\");\n            }\n\n            this.progressiveScans = value;\n        }\n    }\n\n    /// <summary>\n    /// Gets numbers of MCUs between restart markers.\n    /// Defaults to <value>0</value>.\n    /// </summary>\n    /// <remarks>\n    /// Currently supported in progressive encoding only.\n    /// </remarks>\n    /// <exception cref=\"ArgumentException\">Restart interval must be in [0..65535] range.</exception>\n    public int RestartInterval\n    {\n        get => this.restartInterval;\n        init","sourceCodeStart":49,"sourceCodeEnd":85,"githubUrl":"https://github.com/SixLabors/ImageSharp/blob/59ce6af6fc29027cda277ef62d4d1694a8acce91/src/ImageSharp/Formats/Jpeg/JpegEncoder.cs#L49-L85","documentation":"JpegEncoder.ProgressiveScans is init-only validated to be between 2 and 64 inclusive and only applies to progressive JPEG encoding; out-of-range values throw ArgumentException at object-initializer time.","triggerScenarios":"new JpegEncoder { ProgressiveScans = 1 } or > 64, commonly from a scan-count computed dynamically or copied from another encoder's scale where 1 scan means baseline.","commonSituations":"Assuming 1 scan is valid (baseline encoding uses no scan script — omit ProgressiveScans instead); generating scan counts from user input; porting settings from other encoders with different scan semantics.","solutions":["Clamp/validate to [2..64] before assigning","For non-progressive output, leave ProgressiveScans unset instead of passing 1","Derive scan counts from ImageSharp's documented progressive scan script range","Validate config/query-string input before constructing the encoder"],"exampleFix":"// before\nvar encoder = new JpegEncoder { ProgressiveScans = scans }; // ArgumentException if scans < 2\n// after\nvar encoder = new JpegEncoder { ProgressiveScans = Math.Clamp(scans, 2, 64) };","handlingStrategy":"validation","validationCode":"if (scans is < 2 or > 64) throw new ArgumentOutOfRangeException(nameof(scans), \"ProgressiveScans must be in [2..64].\");","typeGuard":"static bool IsValidProgressiveScanCount(int s) => s is >= 2 and <= 64;","tryCatchPattern":null,"preventionTips":["Do not set ProgressiveScans at all for baseline encoding","Clamp computed scan counts to [2..64]","Validate scan-related config at application startup, not per-request"],"tags":["dotnet","jpeg","encoder","argument-out-of-range"],"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"}