Coverage Report

Created: 2026-12-01 07:23

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/libavif/src/properties.c
Line
Count
Source
1
// Copyright 2024 Brad Hards. All rights reserved.
2
// SPDX-License-Identifier: BSD-2-Clause
3
4
#include "avif/internal.h"
5
6
#include <string.h>
7
8
struct avifKnownProperty
9
{
10
    uint8_t fourcc[4];
11
};
12
13
static const struct avifKnownProperty knownProperties[] = {
14
    { { 'f', 't', 'y', 'p' } }, { { 'u', 'u', 'i', 'd' } }, { { 'm', 'e', 't', 'a' } }, { { 'h', 'd', 'l', 'r' } },
15
    { { 'p', 'i', 't', 'm' } }, { { 'd', 'i', 'n', 'f' } }, { { 'd', 'r', 'e', 'f' } }, { { 'i', 'd', 'a', 't' } },
16
    { { 'i', 'l', 'o', 'c' } }, { { 'i', 'i', 'n', 'f' } }, { { 'i', 'n', 'f', 'e' } }, { { 'i', 'p', 'r', 'p' } },
17
    { { 'i', 'p', 'c', 'o' } }, { { 'a', 'v', '1', 'C' } }, { { 'a', 'v', '2', 'C' } }, { { 'i', 's', 'p', 'e' } },
18
    { { 'p', 'i', 'x', 'i' } }, { { 'p', 'a', 's', 'p' } }, { { 'c', 'o', 'l', 'r' } }, { { 'a', 'u', 'x', 'C' } },
19
    { { 'c', 'l', 'a', 'p' } }, { { 'i', 'r', 'o', 't' } }, { { 'i', 'm', 'i', 'r' } }, { { 'c', 'l', 'l', 'i' } },
20
    { { 'c', 'c', 'l', 'v' } }, { { 'm', 'd', 'c', 'v' } }, { { 'a', 'm', 'v', 'e' } }, { { 'r', 'e', 'v', 'e' } },
21
    { { 'n', 'd', 'w', 't' } }, { { 'a', '1', 'o', 'p' } }, { { 'l', 's', 'e', 'l' } }, { { 'a', '1', 'l', 'x' } },
22
    { { 'c', 'm', 'i', 'n' } }, { { 'c', 'm', 'e', 'x' } }, { { 'i', 'p', 'm', 'a' } }, { { 'i', 'r', 'e', 'f' } },
23
    { { 'a', 'u', 'x', 'l' } }, { { 't', 'h', 'm', 'b' } }, { { 'd', 'i', 'm', 'g' } }, { { 'p', 'r', 'e', 'm' } },
24
    { { 'c', 'd', 's', 'c' } }, { { 'g', 'r', 'p', 'l' } }, { { 'a', 'l', 't', 'r' } }, { { 's', 't', 'e', 'r' } },
25
    { { 'm', 'd', 'a', 't' } },
26
};
27
28
static const size_t numKnownProperties = sizeof(knownProperties) / sizeof(knownProperties[0]);
29
30
static const size_t FOURCC_BYTES = 4;
31
static const size_t UUID_BYTES = 16;
32
33
static const uint8_t ISO_UUID_SUFFIX[12] = { 0x00, 0x01, 0x00, 0x10, 0x80, 0x00, 0x00, 0xAA, 0x00, 0x38, 0x9b, 0x71 };
34
35
avifBool avifIsKnownPropertyType(const uint8_t boxtype[4])
36
4.03k
{
37
185k
    for (size_t i = 0; i < numKnownProperties; i++) {
38
181k
        if (memcmp(knownProperties[i].fourcc, boxtype, FOURCC_BYTES) == 0) {
39
0
            return AVIF_TRUE;
40
0
        }
41
181k
    }
42
4.03k
    return AVIF_FALSE;
43
4.03k
}
44
45
avifBool avifIsValidUUID(const uint8_t uuid[16])
46
3.13k
{
47
    // This check is to reject encoding a known property via the UUID mechanism
48
    // See ISO/IEC 14496-12 Section 4.2.3
49
143k
    for (size_t i = 0; i < numKnownProperties; i++) {
50
140k
        if ((memcmp(knownProperties[i].fourcc, uuid, FOURCC_BYTES) == 0) &&
51
0
            (memcmp(ISO_UUID_SUFFIX, uuid + FOURCC_BYTES, UUID_BYTES - FOURCC_BYTES) == 0)) {
52
0
            return AVIF_FALSE;
53
0
        }
54
140k
    }
55
    // This check rejects UUIDs with unexpected variant field values, including Nil UUID and Max UUID.
56
    // See RFC 9562 Section 4.1
57
3.13k
    uint8_t variant = uuid[8] >> 4;
58
3.13k
    if ((variant < 0x08) || (variant > 0x0b)) {
59
2.09k
        return AVIF_FALSE;
60
2.09k
    }
61
    // This check rejects UUIDs with unexpected version field values.
62
    // See RFC 9562 Section 4.2
63
1.03k
    uint8_t version = uuid[6] >> 4;
64
1.03k
    if ((version < 1) || (version > 8)) {
65
376
        return AVIF_FALSE;
66
376
    }
67
    // The rest of a UUID is pretty much a bucket of bits, so assume its OK.
68
656
    return AVIF_TRUE;
69
1.03k
}