[FFmpeg-devel] [PATCH v2 1/3] avformat/argo_asf: cleanup and NULL-terminate name field in header

Zane van Iperen zane at zanevaniperen.com
Tue Oct 12 14:02:22 EEST 2021


Signed-off-by: Zane van Iperen <zane at zanevaniperen.com>
---
 libavformat/argo_asf.c | 8 ++++----
 libavformat/argo_asf.h | 3 ++-
 2 files changed, 6 insertions(+), 5 deletions(-)

diff --git a/libavformat/argo_asf.c b/libavformat/argo_asf.c
index 7e759c7c0c..acf30839b9 100644
--- a/libavformat/argo_asf.c
+++ b/libavformat/argo_asf.c
@@ -52,8 +52,8 @@ void ff_argo_asf_parse_file_header(ArgoASFFileHeader *hdr, const uint8_t *buf)
     hdr->version_minor  = AV_RL16(buf + 6);
     hdr->num_chunks     = AV_RL32(buf + 8);
     hdr->chunk_offset   = AV_RL32(buf + 12);
-    for (int i = 0; i < FF_ARRAY_ELEMS(hdr->name); i++)
-        hdr->name[i]    = AV_RL8(buf + 16 + i);
+    memcpy(hdr->name, buf + 16, ASF_NAME_SIZE);
+    hdr->name[ASF_NAME_SIZE] = '\0';
 }
 
 int ff_argo_asf_validate_file_header(AVFormatContext *s, const ArgoASFFileHeader *hdr)
@@ -331,7 +331,7 @@ static void argo_asf_write_file_header(const ArgoASFFileHeader *fhdr, AVIOContex
     avio_wl16( pb, fhdr->version_minor);
     avio_wl32( pb, fhdr->num_chunks);
     avio_wl32( pb, fhdr->chunk_offset);
-    avio_write(pb, fhdr->name, sizeof(fhdr->name));
+    avio_write(pb, fhdr->name, ASF_NAME_SIZE);
 }
 
 static void argo_asf_write_chunk_header(const ArgoASFChunkHeader *ckhdr, AVIOContext *pb)
@@ -368,7 +368,7 @@ static int argo_asf_write_header(AVFormatContext *s)
     } else {
         len = end - name;
     }
-    memcpy(fhdr.name, name, FFMIN(len, sizeof(fhdr.name)));
+    memcpy(fhdr.name, name, FFMIN(len, ASF_NAME_SIZE));
 
     chdr.num_blocks    = 0;
     chdr.num_samples   = ASF_SAMPLE_COUNT;
diff --git a/libavformat/argo_asf.h b/libavformat/argo_asf.h
index e65125fb79..1fab31a90b 100644
--- a/libavformat/argo_asf.h
+++ b/libavformat/argo_asf.h
@@ -33,6 +33,7 @@
 #define ASF_CHUNK_HEADER_SIZE   20
 #define ASF_SAMPLE_COUNT        32
 #define ASF_MIN_BUFFER_SIZE     FFMAX(ASF_FILE_HEADER_SIZE, ASF_CHUNK_HEADER_SIZE)
+#define ASF_NAME_SIZE           8
 
 typedef struct ArgoASFFileHeader {
     uint32_t    magic;          /*< Magic Number, {'A', 'S', 'F', '\0'} */
@@ -40,7 +41,7 @@ typedef struct ArgoASFFileHeader {
     uint16_t    version_minor;  /*< File Minor Version. */
     uint32_t    num_chunks;     /*< No. chunks in the file. */
     uint32_t    chunk_offset;   /*< Offset to the first chunk from the start of the file. */
-    int8_t      name[8];        /*< Name. */
+    char        name[ASF_NAME_SIZE + 1]; /*< Name, +1 for NULL-terminator. */
 } ArgoASFFileHeader;
 
 typedef struct ArgoASFChunkHeader {
-- 
2.31.1



More information about the ffmpeg-devel mailing list