AnkiIO 1.0.2
Build, validate, import, and export Anki-compatible decks from .NET
Loading...
Searching...
No Matches
AnkiIO.AnkiPackageLimits Class Referencesealed

Defines archive-resource limits enforced before an untrusted Anki package is extracted. More...

Public Member Functions

 AnkiPackageLimits ()
 Initializes the documented default archive limits.

Properties

static AnkiPackageLimits Default = new() [get]
 Gets the shared default limits.
int MaximumEntries [get]
 Gets the largest permitted number of ZIP entries.
long MaximumEntryBytes [get]
 Gets the largest permitted declared uncompressed length of one ZIP entry.
long MaximumTotalBytes [get]
 Gets the largest permitted sum of all declared uncompressed ZIP entry lengths.
double MaximumCompressionRatio [get]
 Gets the largest permitted uncompressed-to-compressed ratio for a non-empty ZIP entry.
long MaximumCollectionBytes [get]
 Gets the largest permitted declared uncompressed length of collection.anki2.

Detailed Description

Defines archive-resource limits enforced before an untrusted Anki package is extracted.

The reader checks ZIP entry count, each declared uncompressed length, the sum of declared uncompressed lengths, uncompressed-to-compressed ratio, and the declared collection database length. Bounds are inclusive. A non-empty entry claiming zero compressed bytes is treated as an infinite ratio and rejected.

These controls mitigate common ZIP-bomb and oversized-archive attacks; they are not a general sandbox. They do not make malformed ZIP, JSON, or SQLite content valid, bound every SQLite operation, guarantee a particular allocation pattern, or protect against application code that later retains the mutable result indefinitely. Media is eagerly copied into memory, so lower the byte limits for services with a smaller memory budget.

Instances are immutable after initialization. Every configured value is validated immediately, including values set by a record with expression. Counts and byte bounds must be positive. The ratio must be finite and positive.

Restrict an upload endpoint to a 64 MiB archive expansion budget and a 50:1 ratio:

var limits = AnkiPackageLimits.Default with
{
MaximumEntries = 2_000,
MaximumEntryBytes = 32L * 1024 * 1024,
MaximumTotalBytes = 64L * 1024 * 1024,
MaximumCollectionBytes = 32L * 1024 * 1024,
};
var package = await AnkiPackageReader.ReadAsync(uploadStream, limits);
double MaximumCompressionRatio
Gets the largest permitted uncompressed-to-compressed ratio for a non-empty ZIP entry.
int MaximumEntries
Gets the largest permitted number of ZIP entries.
long MaximumTotalBytes
Gets the largest permitted sum of all declared uncompressed ZIP entry lengths.
static AnkiPackageLimits Default
Gets the shared default limits.
long MaximumEntryBytes
Gets the largest permitted declared uncompressed length of one ZIP entry.
long MaximumCollectionBytes
Gets the largest permitted declared uncompressed length of collection.anki2.

Definition at line 35 of file AnkiPackageLimits.cs.

Constructor & Destructor Documentation

◆ AnkiPackageLimits()

AnkiIO.AnkiPackageLimits.AnkiPackageLimits ( )
inline

Initializes the documented default archive limits.

Definition at line 44 of file AnkiPackageLimits.cs.

Property Documentation

◆ Default

AnkiPackageLimits AnkiIO.AnkiPackageLimits.Default = new()
staticget

Gets the shared default limits.

An immutable instance with the values documented on each property.

Use a record with expression to derive per-operation limits without changing this instance.

Definition at line 51 of file AnkiPackageLimits.cs.

◆ MaximumCollectionBytes

long AnkiIO.AnkiPackageLimits.MaximumCollectionBytes
get

Gets the largest permitted declared uncompressed length of collection.anki2.

An inclusive positive byte bound. The default is 512 MiB.

This database-specific bound is applied in addition to the per-entry and total archive bounds.

Exceptions
ArgumentOutOfRangeExceptionThe assigned value is zero or negative.

Definition at line 106 of file AnkiPackageLimits.cs.

◆ MaximumCompressionRatio

double AnkiIO.AnkiPackageLimits.MaximumCompressionRatio
get

Gets the largest permitted uncompressed-to-compressed ratio for a non-empty ZIP entry.

An inclusive finite positive ratio. The default is 200.

For example, a value of 50 permits an entry declaring at most 50 uncompressed bytes per compressed byte. A non-empty entry declaring zero compressed bytes is rejected regardless of this value.

Exceptions
ArgumentOutOfRangeExceptionThe assigned value is non-finite, zero, or negative.

Definition at line 88 of file AnkiPackageLimits.cs.

◆ MaximumEntries

int AnkiIO.AnkiPackageLimits.MaximumEntries
get

Gets the largest permitted number of ZIP entries.

An inclusive positive bound. The default is 10,000 entries.

Exceptions
ArgumentOutOfRangeExceptionThe assigned value is zero or negative.

Definition at line 56 of file AnkiPackageLimits.cs.

◆ MaximumEntryBytes

long AnkiIO.AnkiPackageLimits.MaximumEntryBytes
get

Gets the largest permitted declared uncompressed length of one ZIP entry.

An inclusive positive byte bound. The default is 256 MiB.

Exceptions
ArgumentOutOfRangeExceptionThe assigned value is zero or negative.

Definition at line 65 of file AnkiPackageLimits.cs.

◆ MaximumTotalBytes

long AnkiIO.AnkiPackageLimits.MaximumTotalBytes
get

Gets the largest permitted sum of all declared uncompressed ZIP entry lengths.

An inclusive positive byte bound. The default is 2 GiB.

This aggregate includes the collection database, media map, media payloads, and unsupported entries.

Exceptions
ArgumentOutOfRangeExceptionThe assigned value is zero or negative.

Definition at line 75 of file AnkiPackageLimits.cs.


The documentation for this class was generated from the following file: