Skip to content

AccessViolationException when applying adaptive histogram to large images #1429

@nullpainter

Description

@nullpainter

Prerequisites

  • I have written a descriptive issue title
  • I have verified that I am running the latest version of ImageSharp
  • I have verified if the problem exist in both DEBUG and RELEASE mode
  • I have searched open and closed issues to ensure it has not already been reported

Description

When applying an adaptive histogram equalisation to a 21,969 x 9802px image, I receive the following:

Unhandled Exception: System.AccessViolationException: Attempted to read or write protected memory. This is often an indication that other memory is corrupt.
   at SixLabors.ImageSharp.Processing.Processors.Normalization.AdaptiveHistogramEqualizationProcessor`1.CdfTileData.RowIntervalOperation.Invoke(RowInterval& rows)
   at SixLabors.ImageSharp.Advanced.ParallelRowIterator.RowIntervalOperationWrapper`1.Invoke(Int32 i)
   at System.Threading.Tasks.Parallel.<>c__DisplayClass17_0`1.<ForWorker>b__1()
   at System.Threading.Tasks.Task.InnerInvokeWithArg(Task childTask)
   at System.Threading.Tasks.Task.<>c__DisplayClass176_0.<ExecuteSelfReplicating>b__0(Object <p0>)
   at System.Threading.Tasks.Task.Execute()
   at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
   at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
   at System.Threading.Tasks.Task.ExecuteWithThreadLocal(Task& currentTaskSlot)
   at System.Threading.Tasks.Task.ExecuteEntry(Boolean bPreventDoubleExecution)
   at System.Threading.ThreadPoolWorkQueue.Dispatch()

Steps to Reproduce

This can be easily replicated using the following code, which fails fast:

using var image = new Image<Rgba32>(20000, 10000);
image.Mutate(c => c.HistogramEqualization(new HistogramEqualizationOptions
{
    Method = HistogramEqualizationMethod.AdaptiveTileInterpolation, 
    ClipHistogram = true
}));

I haven't looked at the code at all, but given the speed at which this fails compared with the length of time it takes to equalise a 10,000px square image, I am assuming this crash happens early in the process during memory allocation.

(Apologies for attempting to process gigantic images)

System Configuration

  • ImageSharp version: 1.0.2
  • Other ImageSharp packages and versions:
  • Environment (Operating system, version and so on): Windows 10
  • .NET Framework version: .NET Core 5.0

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions