AVIF Parsing Memory Leaks and Buffer Overflows

This article examines common edge cases encountered when parsing AVIF (AV1 Image File Format) files that frequently result in memory leaks, heap corruptions, and buffer overflows. By analyzing the structural complexities of the underlying ISO Base Media File Format (ISOBMFF) container and the embedded AV1 bitstream, this overview highlights the primary failure modes in memory allocation, pointer arithmetic, and cleanup logic.

1. Integer Overflows in Grid Image Dimensions

AVIF supports tiling large images using the grid derived item reference. The parser reads properties specifying the number of rows, columns, and tile dimensions.

2. Truncated and Inconsistent Box Sizes in ISOBMFF

The ISOBMFF container consists of nested data structures called "boxes" (or atoms), each defining its length and four-character code (FourCC).

3. Circular References and Deeply Nested Boxes

Certain metadata boxes, such as iprp (item properties) and iref (item references), can point to other items or boxes.

4. Asymmetric Item Location (iloc) Specifications

The iloc box maps image items to specific byte ranges and offsets within the file or within the idat (item data) box.

5. Incomplete Cleanup on Decode Interruption

AVIF parsing is a multi-stage process: container parsing, property extraction, decoder initialization (such as libaom or dav1d), and raster output generation.

Mitigation Strategies

Preventing these vulnerabilities requires standard defensive parsing patterns: