{"record":{"id":"56392326615365be","repo":"SixLabors/ImageSharp","slug":"column-regions-should-not-overlap","errorCode":null,"errorMessage":"Column regions should not overlap!","messagePattern":"Column regions should not overlap!","errorType":"validation","errorClass":"InvalidOperationException","httpStatus":null,"severity":"error","filePath":"src/ImageSharp/Memory/Buffer2DExtensions.cs","lineNumber":153,"sourceCode":"    /// <param name=\"buffer\">The <see cref=\"Buffer2D{T}\"/></param>\n    /// <returns>The <see cref=\"Buffer2DRegion{T}\"/></returns>\n    public static Buffer2DRegion<T> GetRegion<T>(this Buffer2D<T> buffer)\n        where T : unmanaged =>\n        new(buffer);\n\n    [Conditional(\"DEBUG\")]\n    private static void CheckColumnRegionsDoNotOverlap<T>(\n        Buffer2D<T> buffer,\n        int sourceIndex,\n        int destIndex,\n        int columnCount)\n        where T : struct\n    {\n        int minIndex = Math.Min(sourceIndex, destIndex);\n        int maxIndex = Math.Max(sourceIndex, destIndex);\n        if (maxIndex < minIndex + columnCount || maxIndex > buffer.Width - columnCount)\n        {\n            throw new InvalidOperationException(\"Column regions should not overlap!\");\n        }\n    }\n}\n","sourceCodeStart":135,"sourceCodeEnd":157,"githubUrl":"https://github.com/SixLabors/ImageSharp/blob/59ce6af6fc29027cda277ef62d4d1694a8acce91/src/ImageSharp/Memory/Buffer2DExtensions.cs#L135-L157","documentation":"Buffer2DExtensions.DangerousCopyColumns validates that the source and destination column regions neither overlap each other nor extend past the buffer edges. Overlapping column copies cannot be performed safely with the single-pass copy used, so InvalidOperationException is thrown.","triggerScenarios":"Calling DangerousCopyColumns/CopyColumns where sourceIndex and destIndex ranges overlap (e.g. copy 5 columns from x=0 to x=3) or where maxIndex + columnCount exceeds buffer.Width.","commonSituations":"Implementing custom pixel-shifting/sliding operations on image columns with ranges computed at runtime.","solutions":["Validate that maxIndex < minIndex + columnCount and maxIndex <= buffer.Width - columnCount before calling","Copy to a temporary buffer first when overlapping shifts are intended","Reduce columnCount so the regions are disjoint"],"exampleFix":"// before\nbuffer.DangerousCopyColumns(0, 3, 5);\n// after\nif (Math.Max(0, 3) < 3 + 5) { /* copy via temp buffer or adjust indices */ }\nbuffer.DangerousCopyColumns(0, 5, 5);","handlingStrategy":"validation","validationCode":"bool ok = Math.Max(src, dst) < Math.Min(src, dst) + count && Math.Max(src, dst) <= buffer.Width - count;","typeGuard":"bool canCopyColumns<T>(Buffer2D<T> b, int src, int dst, int count) => Math.Max(src, dst) < Math.Min(src, dst) + count && Math.Max(src, dst) <= b.Width - count;","tryCatchPattern":"try { buffer.DangerousCopyColumns(src, dst, count); } catch (InvalidOperationException) { /* use temp-buffer copy */ }","preventionTips":["Compute column ranges with min/max checks before copying","Use a staging buffer when overlap is possible","Clamp count so regions stay inside buffer width"],"tags":["csharp","memory","buffers"],"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-23T08:17:48.524Z"}