PR #26087 opened by fuzzyrichie
URL: https://code.ffmpeg.org/FFmpeg/FFmpeg/pulls/26087
Patch URL: https://code.ffmpeg.org/FFmpeg/FFmpeg/pulls/26087.patch

Replaced the unchecked avio_read() calls for the source KLV key and AES IV with 
ffio_read_size() and propagate short-read errors. This prevents uninitialized 
stack data from being used as the AES IV and stops stale key bytes from passing 
the essence-key check.


>From 9761fe2b76e91778b0f9145398132f1b253e3134 Mon Sep 17 00:00:00 2001
From: Richard Desmarais <[email protected]>
Date: Sun, 15 Nov 2026 18:00:21 -0500
Subject: [PATCH] mxfdec: check reads of encrypted triplet key and IV

---
 libavformat/mxfdec.c | 10 +++++++---
 1 file changed, 7 insertions(+), 3 deletions(-)

diff --git a/libavformat/mxfdec.c b/libavformat/mxfdec.c
index 280a20aad33..7cd3b78055e 100644
--- a/libavformat/mxfdec.c
+++ b/libavformat/mxfdec.c
@@ -684,7 +684,9 @@ static int mxf_decrypt_triplet(AVFormatContext *s, AVPacket 
*pkt, KLVPacket *klv
     plaintext_size = avio_rb64(pb);
     // source klv key
     klv_decode_ber_length(pb, NULL);
-    avio_read(pb, klv->key, 16);
+    ret = ffio_read_size(pb, klv->key, 16);
+    if (ret < 0)
+        return ret;
     if (!IS_KLV_KEY(klv, mxf_essence_element_key))
         return AVERROR_INVALIDDATA;
 
@@ -701,9 +703,11 @@ static int mxf_decrypt_triplet(AVFormatContext *s, 
AVPacket *pkt, KLVPacket *klv
     size = klv_decode_ber_length(pb, NULL);
     if (size < 32 || size - 32 < orig_size || (int)orig_size != orig_size)
         return AVERROR_INVALIDDATA;
-    avio_read(pb, ivec, 16);
+    ret = ffio_read_size(pb, ivec, 16);
+    if (ret < 0)
+        return ret;
     ret = ffio_read_size(pb, tmpbuf, 16);
-    if (ret < 16)
+    if (ret < 0)
         return ret;
     if (mxf->aesc)
         av_aes_crypt(mxf->aesc, tmpbuf, tmpbuf, 1, ivec, 1);
-- 
2.54.0

_______________________________________________
ffmpeg-devel mailing list -- [email protected]
To unsubscribe send an email to [email protected]

Reply via email to