diff --git a/libavformat/mxfdec.c b/libavformat/mxfdec.c
index 1f583b8ad63ce10fbc330cb7ede7dc29e8b22fbe..3f6b7d9b5eb963d533df45fc83ad57f2acf9d58b 100644
--- a/libavformat/mxfdec.c
+++ b/libavformat/mxfdec.c
@@ -782,14 +782,14 @@ static int mxf_read_index_table_segment(void *arg, AVIOContext *pb, int tag, int
 static void mxf_read_pixel_layout(AVIOContext *pb, MXFDescriptor *descriptor)
 {
     int code, value, ofs = 0;
-    char layout[16] = {0};
+    char layout[16] = {0}; /* not for printing, may end up not terminated on purpose */
 
     do {
         code = avio_r8(pb);
         value = avio_r8(pb);
         av_dlog(NULL, "pixel layout: code %#x\n", code);
 
-        if (ofs < 16) {
+        if (ofs <= 14) {
             layout[ofs++] = code;
             layout[ofs++] = value;
         }