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. | |
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:
Definition at line 35 of file AnkiPackageLimits.cs.
|
inline |
Initializes the documented default archive limits.
Definition at line 44 of file AnkiPackageLimits.cs.
|
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.
|
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.
| ArgumentOutOfRangeException | The assigned value is zero or negative. |
Definition at line 106 of file AnkiPackageLimits.cs.
|
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.
| ArgumentOutOfRangeException | The assigned value is non-finite, zero, or negative. |
Definition at line 88 of file AnkiPackageLimits.cs.
|
get |
Gets the largest permitted number of ZIP entries.
An inclusive positive bound. The default is 10,000 entries.
| ArgumentOutOfRangeException | The assigned value is zero or negative. |
Definition at line 56 of file AnkiPackageLimits.cs.
|
get |
Gets the largest permitted declared uncompressed length of one ZIP entry.
An inclusive positive byte bound. The default is 256 MiB.
| ArgumentOutOfRangeException | The assigned value is zero or negative. |
Definition at line 65 of file AnkiPackageLimits.cs.
|
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.
| ArgumentOutOfRangeException | The assigned value is zero or negative. |
Definition at line 75 of file AnkiPackageLimits.cs.