Skip to content

Commit 2d48c03

Browse files
committed
Use const pointers with codec->csOptions
Ensure that the codecs cannot modify codec->csOptions, which they do not own.
1 parent 3e30bc6 commit 2d48c03

5 files changed

Lines changed: 10 additions & 10 deletions

File tree

include/avif/internal.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -597,10 +597,10 @@ typedef void (*avifCodecDestroyInternalFunc)(struct avifCodec * codec);
597597

598598
typedef struct avifCodec
599599
{
600-
avifCodecSpecificOptions * csOptions; // Contains codec-specific key/value pairs for advanced tuning.
601-
// This array is NOT owned by avifCodec.
602-
struct avifCodecInternal * internal; // up to each codec to use how it wants
603-
avifDiagnostics * diag; // Shallow copy; owned by avifEncoder or avifDecoder
600+
const avifCodecSpecificOptions * csOptions; // Contains codec-specific key/value pairs for advanced tuning.
601+
// This array is NOT owned by avifCodec.
602+
struct avifCodecInternal * internal; // up to each codec to use how it wants
603+
avifDiagnostics * diag; // Shallow copy; owned by avifEncoder or avifDecoder
604604

605605
// Decoder options (for getNextImage):
606606
int maxThreads; // See avifDecoder::maxThreads.

src/codec_aom.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -390,7 +390,7 @@ static avifBool avifAOMOptionsContainExplicitTuning(const avifCodec * codec, avi
390390
static avifBool avifProcessAOMOptionsPreInit(avifCodec * codec, avifBool alpha, struct aom_codec_enc_cfg * cfg)
391391
{
392392
for (uint32_t i = 0; i < codec->csOptions->count; ++i) {
393-
avifCodecSpecificOption * entry = &codec->csOptions->entries[i];
393+
const avifCodecSpecificOption * entry = &codec->csOptions->entries[i];
394394
int val;
395395
if (avifKeyEqualsName(entry->key, "end-usage", alpha)) { // Rate control mode
396396
if (!aomOptionParseEnum(entry->value, endUsageEnum, &val)) {
@@ -484,7 +484,7 @@ static const struct aomOptionDef aomOptionDefs[] = {
484484
static avifBool avifProcessAOMOptionsPostInit(avifCodec * codec, avifBool alpha)
485485
{
486486
for (uint32_t i = 0; i < codec->csOptions->count; ++i) {
487-
avifCodecSpecificOption * entry = &codec->csOptions->entries[i];
487+
const avifCodecSpecificOption * entry = &codec->csOptions->entries[i];
488488
// Skip options for the other kind of plane.
489489
const char * otherPrefix = alpha ? "color:" : "alpha:";
490490
size_t otherPrefixLen = 6;

src/codec_avm.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -341,7 +341,7 @@ static avifBool avifKeyEqualsName(const char * key, const char * name, avifBool
341341
static avifBool avifProcessAVMOptionsPreInit(avifCodec * codec, avifBool alpha, struct avm_codec_enc_cfg * cfg)
342342
{
343343
for (uint32_t i = 0; i < codec->csOptions->count; ++i) {
344-
avifCodecSpecificOption * entry = &codec->csOptions->entries[i];
344+
const avifCodecSpecificOption * entry = &codec->csOptions->entries[i];
345345
int val;
346346
if (avifKeyEqualsName(entry->key, "end-usage", alpha)) { // Rate control mode
347347
if (!avmOptionParseEnum(entry->value, endUsageEnum, &val)) {
@@ -357,7 +357,7 @@ static avifBool avifProcessAVMOptionsPreInit(avifCodec * codec, avifBool alpha,
357357
static avifBool avifProcessAVMOptionsPostInit(avifCodec * codec, avifBool alpha)
358358
{
359359
for (uint32_t i = 0; i < codec->csOptions->count; ++i) {
360-
avifCodecSpecificOption * entry = &codec->csOptions->entries[i];
360+
const avifCodecSpecificOption * entry = &codec->csOptions->entries[i];
361361
// Skip options for the other kind of plane.
362362
const char * otherPrefix = alpha ? "color:" : "alpha:";
363363
size_t otherPrefixLen = 6;

src/codec_rav1e.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -202,7 +202,7 @@ static avifResult rav1eCodecEncodeImage(avifCodec * codec,
202202
}
203203
}
204204
for (uint32_t i = 0; i < codec->csOptions->count; ++i) {
205-
avifCodecSpecificOption * entry = &codec->csOptions->entries[i];
205+
const avifCodecSpecificOption * entry = &codec->csOptions->entries[i];
206206
if (rav1e_config_parse(rav1eConfig, entry->key, entry->value) < 0) {
207207
avifDiagnosticsPrintf(codec->diag, "Invalid value for %s: %s.", entry->key, entry->value);
208208
result = AVIF_RESULT_INVALID_CODEC_SPECIFIC_OPTION;

src/codec_svt.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -228,7 +228,7 @@ static avifResult svtCodecEncodeImage(avifCodec * codec,
228228

229229
#if SVT_AV1_CHECK_VERSION(0, 9, 1)
230230
for (uint32_t i = 0; i < codec->csOptions->count; ++i) {
231-
avifCodecSpecificOption * entry = &codec->csOptions->entries[i];
231+
const avifCodecSpecificOption * entry = &codec->csOptions->entries[i];
232232
if (svt_av1_enc_parse_parameter(svt_config, entry->key, entry->value) < 0) {
233233
avifDiagnosticsPrintf(codec->diag, "Invalid value for %s: %s.", entry->key, entry->value);
234234
result = AVIF_RESULT_INVALID_CODEC_SPECIFIC_OPTION;

0 commit comments

Comments
 (0)