{"record":{"id":"1f00b9b5f81801e1","repo":"SixLabors/ImageSharp","slug":"not-a-valid-pass-index-passindex","errorCode":null,"errorMessage":"Not a valid pass index: {passIndex}","messagePattern":"Not a valid pass index: (.+?)","errorType":"exception","errorClass":"ArgumentException","httpStatus":null,"severity":"error","filePath":"src/ImageSharp/Formats/Png/Adam7.cs","lineNumber":86,"sourceCode":"    public static int ComputeColumns(int width, int passIndex)\n    {\n        uint w = (uint)width;\n\n        uint result = passIndex switch\n        {\n            0 => (w + 7) / 8,\n            1 => (w + 3) / 8,\n            2 => (w + 3) / 4,\n            3 => (w + 1) / 4,\n            4 => (w + 1) / 2,\n            5 => w / 2,\n            6 => w,\n            _ => Throw(passIndex)\n        };\n\n        return (int)result;\n\n        static uint Throw(int passIndex) => throw new ArgumentException($\"Not a valid pass index: {passIndex}\");\n    }\n}\n","sourceCodeStart":68,"sourceCodeEnd":89,"githubUrl":"https://github.com/SixLabors/ImageSharp/blob/59ce6af6fc29027cda277ef62d4d1694a8acce91/src/ImageSharp/Formats/Png/Adam7.cs#L68-L89","documentation":"Adam7.ComputeColumns throws this ArgumentException when the pass index is outside 0-6. The Adam7 interlacing scheme in PNG has exactly seven passes, and ComputeColumns maps each pass index to the number of columns it processes; any other index is a programming error. This is an internal argument validation, not a data-content error.","triggerScenarios":"Calling Adam7.ComputeColumns (or the Adam7 encoding/decoding paths that forward to it) with a passIndex < 0 or > 6, typically via an incorrectly written or modified interlace loop.","commonSituations":"Custom PNG codec modifications, porting Adam7 code from another library with 1-based pass numbering, or a loop bug such as `for (int pass = 0; pass <= 7; pass++)`.","solutions":["Use pass indices 0 through 6 only; fix the loop bounds driving the call.","If porting from 1-based code, subtract 1 before calling ComputeColumns.","Use the library's established interlace iteration helpers instead of hand-rolled pass loops."],"exampleFix":"// before: 1-based pass numbering leaking in\nfor (int pass = 1; pass <= 7; pass++)\n    int columns = Adam7.ComputeColumns(width, pass); // throws for pass == 7\n// after\nfor (int pass = 0; pass < 7; pass++)\n    int columns = Adam7.ComputeColumns(width, pass);","handlingStrategy":"type-guard","validationCode":"// passIndex must be 0-6 for Adam7's seven passes\nif (passIndex is < 0 or > 6)\n    throw new ArgumentOutOfRangeException(nameof(passIndex), passIndex, \"Adam7 has passes 0..6\");","typeGuard":"static bool IsValidAdam7Pass(int passIndex) => (uint)passIndex < 7u;","tryCatchPattern":"try\n{\n    columns = Adam7.ComputeColumns(width, pass);\n}\ncatch (ArgumentException ex)\n{\n    throw new InvalidOperationException($\"Interlace loop produced invalid pass index: {ex.Message}\", ex);\n}","preventionTips":["Always iterate Adam7 passes as `for (int pass = 0; pass < 7; pass++)`.","Convert 1-based pass numbers from other libraries with `pass - 1` at the boundary.","Prefer the library's interlace helper APIs over hand-rolled pass math."],"tags":["png","adam7","interlacing","argument-validation"],"backgroundTag":"invalid-argument-value","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"}