From b01a8af573c752f1e0103262531ee08a90b5af08 Mon Sep 17 00:00:00 2001 From: Vincent Rabaud Date: Mon, 22 Jan 2024 23:03:41 +0100 Subject: [PATCH] Properly check if an identical chunk has been written before. (#1956) Basically reverting 295cab3 in https://github.com/AOMediaCodec/libavif/pull/463 --- src/write.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/write.c b/src/write.c index cd5c4719c5..015d83e120 100644 --- a/src/write.c +++ b/src/write.c @@ -1816,10 +1816,11 @@ static avifResult avifEncoderWriteMediaDataBox(avifEncoder * encoder, size_t chunkOffset = 0; // Deduplication - See if an identical chunk to this has already been written - if (item->encodeOutput->samples.count > 0) { + // Doing it when item->encodeOutput->samples.count > 0 would require contiguous memory. + if (item->encodeOutput->samples.count == 1) { avifEncodeSample * sample = &item->encodeOutput->samples.sample[0]; chunkOffset = avifEncoderFindExistingChunk(s, mdatStartOffset, sample->data.data, sample->data.size); - } else { + } else if (item->encodeOutput->samples.count == 0) { chunkOffset = avifEncoderFindExistingChunk(s, mdatStartOffset, item->metadataPayload.data, item->metadataPayload.size); }