Browse Source

add guards to verify scanlineBuffer size

pull/140/head
Scott Williams 9 years ago
parent
commit
a6e4de8d56
  1. 7
      src/ImageSharp.Drawing/Brushes/ImageBrush{TColor}.cs
  2. 7
      src/ImageSharp.Drawing/Brushes/PatternBrush{TColor}.cs
  3. 9
      src/ImageSharp.Drawing/Brushes/Processors/BrushApplicator.cs
  4. 7
      src/ImageSharp.Drawing/Brushes/RecolorBrush{TColor}.cs
  5. 7
      src/ImageSharp.Drawing/Brushes/SolidBrush{TColor}.cs

7
src/ImageSharp.Drawing/Brushes/ImageBrush{TColor}.cs

@ -112,9 +112,12 @@ namespace ImageSharp.Drawing.Brushes
this.source.Dispose();
}
internal override void Apply(float[] scanline, int scanlineWidth, int offset, int x, int y)
/// <inheritdoc />
internal override void Apply(float[] scanlineBuffer, int scanlineWidth, int offset, int x, int y)
{
using (PinnedBuffer<float> buffer = new PinnedBuffer<float>(scanline))
DebugGuard.MustBeGreaterThanOrEqualTo(scanlineBuffer.Length, offset + scanlineWidth, nameof(scanlineWidth));
using (PinnedBuffer<float> buffer = new PinnedBuffer<float>(scanlineBuffer))
{
BufferPointer<float> slice = buffer.Slice(offset);

7
src/ImageSharp.Drawing/Brushes/PatternBrush{TColor}.cs

@ -144,9 +144,12 @@ namespace ImageSharp.Drawing.Brushes
// noop
}
internal override void Apply(float[] scanline, int scanlineWidth, int offset, int x, int y)
/// <inheritdoc />
internal override void Apply(float[] scanlineBuffer, int scanlineWidth, int offset, int x, int y)
{
using (PinnedBuffer<float> buffer = new PinnedBuffer<float>(scanline))
DebugGuard.MustBeGreaterThanOrEqualTo(scanlineBuffer.Length, offset + scanlineWidth, nameof(scanlineWidth));
using (PinnedBuffer<float> buffer = new PinnedBuffer<float>(scanlineBuffer))
{
BufferPointer<float> slice = buffer.Slice(offset);

9
src/ImageSharp.Drawing/Brushes/Processors/BrushApplicator.cs

@ -45,14 +45,17 @@ namespace ImageSharp.Drawing.Processors
/// <summary>
/// Applies the opactiy weighting for each pixel in a scanline to the target based on the pattern contained in the brush.
/// </summary>
/// <param name="scanline">The a collection of opacity values between 0 and 1 to be merged with the burshed color value before being applied to the target.</param>
/// <param name="scanlineBuffer">The a collection of opacity values between 0 and 1 to be merged with the brushed color value before being applied to the target.</param>
/// <param name="scanlineWidth">The number of pixels effected by this scanline.</param>
/// <param name="offset">The offset fromthe begining of <paramref name="scanline" /> the opacity data starts.</param>
/// <param name="x">The x position in the target pixel space that the start of the scanline data corresponds to.</param>
/// <param name="y">The y position in the target pixel space that whole scanline corresponds to.</param>
internal virtual void Apply(float[] scanline, int scanlineWidth, int offset, int x, int y)
/// <remarks>scanlineBuffer will be > scanlineWidth but provide and offset in case we want to share a larger buffer across runs.</remarks>
internal virtual void Apply(float[] scanlineBuffer, int scanlineWidth, int offset, int x, int y)
{
using (PinnedBuffer<float> buffer = new PinnedBuffer<float>(scanline))
DebugGuard.MustBeGreaterThanOrEqualTo(scanlineBuffer.Length, offset + scanlineWidth, nameof(scanlineWidth));
using (PinnedBuffer<float> buffer = new PinnedBuffer<float>(scanlineBuffer))
{
BufferPointer<float> slice = buffer.Slice(offset);

7
src/ImageSharp.Drawing/Brushes/RecolorBrush{TColor}.cs

@ -136,9 +136,12 @@ namespace ImageSharp.Drawing.Brushes
{
}
internal override void Apply(float[] scanline, int scanlineWidth, int offset, int x, int y)
/// <inheritdoc />
internal override void Apply(float[] scanlineBuffer, int scanlineWidth, int offset, int x, int y)
{
using (PinnedBuffer<float> buffer = new PinnedBuffer<float>(scanline))
DebugGuard.MustBeGreaterThanOrEqualTo(scanlineBuffer.Length, offset + scanlineWidth, nameof(scanlineWidth));
using (PinnedBuffer<float> buffer = new PinnedBuffer<float>(scanlineBuffer))
{
BufferPointer<float> slice = buffer.Slice(offset);

7
src/ImageSharp.Drawing/Brushes/SolidBrush{TColor}.cs

@ -84,9 +84,12 @@ namespace ImageSharp.Drawing.Brushes
// noop
}
internal override void Apply(float[] scanline, int scanlineWidth, int offset, int x, int y)
/// <inheritdoc />
internal override void Apply(float[] scanlineBuffer, int scanlineWidth, int offset, int x, int y)
{
using (PinnedBuffer<float> buffer = new PinnedBuffer<float>(scanline))
DebugGuard.MustBeGreaterThanOrEqualTo(scanlineBuffer.Length, offset + scanlineWidth, nameof(scanlineWidth));
using (PinnedBuffer<float> buffer = new PinnedBuffer<float>(scanlineBuffer))
{
BufferPointer<float> slice = buffer.Slice(offset);

Loading…
Cancel
Save