Class SafetyLimits
- Namespace
- Egami
- Assembly
- Egami.dll
Limits that protect against hostile or broken files. Readers check sizes from the header before allocating any pixel memory.
The defaults let normal photos and screenshots through. Change them with a with expression.
public sealed record SafetyLimits : IEquatable<SafetyLimits>
- Inheritance
-
SafetyLimits
- Implements
- Inherited Members
Examples
EgamiContext strict = EgamiContext.Default with
{
Limits = SafetyLimits.Default with { MaxPixels = 25_000_000, MaxTotalBytes = 256L * 1024 * 1024 },
};
try
{
// Read the header first: cheap, and it rejects what you do not want before any pixel memory is used.
RasterInfo info = Raster.Probe(upload, strict);
if (info.Width > 8000 || info.Height > 8000)
{
throw new InvalidDataException("Too large.");
}
using Raster image = Raster.Load(upload, strict, new ReaderOptions { Recovery = RecoveryMode.Strict });
Console.WriteLine($"{info.Format.Name} {image.Width} × {image.Height}");
}
catch (UnsupportedFormatException)
{
Console.WriteLine("Not an image format we accept.");
}
catch (LimitExceededException e)
{
Console.WriteLine($"Over the {e.LimitName} limit.");
}
catch (CorruptDataException e)
{
Console.WriteLine($"Damaged at byte {e.Offset}.");
}
Remarks
Limits apply to reading. Operations (Apply, Derive) and adding frames check MaxTotalBytes too;
writers check nothing. Every limit must be at least 1; setting a smaller value throws ArgumentOutOfRangeException.
Properties
Default
Gets the default limits.
public static SafetyLimits Default { get; }
Property Value
MaxFrames
Gets the largest number of frames. Defaults to 10,000.
public int MaxFrames { get; init; }
Property Value
MaxHeight
Gets the largest height, in pixels. Defaults to 65,535.
public int MaxHeight { get; init; }
Property Value
MaxMetadataBytes
Gets the largest total size, in bytes, of metadata such as EXIF, ICC, XMP and text. Defaults to 16 MB.
public long MaxMetadataBytes { get; init; }
Property Value
MaxPixels
Gets the largest number of pixels in one frame. Defaults to 268,435,456 (16,384 × 16,384).
public long MaxPixels { get; init; }
Property Value
MaxTotalBytes
Gets the most memory, in bytes, that one load or one chain of operations may hold at once, counting all frames and temporary buffers. Defaults to 2 GB.
public long MaxTotalBytes { get; init; }
Property Value
MaxWidth
Gets the largest width, in pixels. Defaults to 65,535.
public int MaxWidth { get; init; }