[PR] avformat/{ape,shared}: Don't log incomplete lines (PR #24180)

mkver via ffmpeg-devel <[email protected]>
Newsgroups gmane.comp.video.ffmpeg.devel
Message-ID <[email protected]>
PR #24180 opened by mkver
URL: https://code.ffmpeg.org/FFmpeg/FFmpeg/pulls/24180
Patch URL: https://code.ffmpeg.org/FFmpeg/FFmpeg/pulls/24180.patch

Also use ff_data_to_hex() in smoothstreamingenc.


>From 4213c1d24c72b10c106e1c9f0e37082eee2c0bbf Mon Sep 17 00:00:00 2001
From: Andreas Rheinhardt <[email protected]>
Date: Mon, 17 Aug 2026 03:56:47 +0200
Subject: [PATCH 1/4] avformat/shared: Don't log incomplete lines

Incomplete lines (without \n) may be torn apart by av_log()s
from other threads. So log them once. Also use ff_data_to_hex()
for the data->hex conversion.

Signed-off-by: Andreas Rheinhardt <[email protected]>
---
 libavformat/shared.c | 16 +++++++++-------
 1 file changed, 9 insertions(+), 7 deletions(-)

diff --git a/libavformat/shared.c b/libavformat/shared.c
index 5fd01b185e..fbe86ff1dc 100644
--- a/libavformat/shared.c
+++ b/libavformat/shared.c
@@ -32,6 +32,7 @@
 #include "libavutil/opt.h"
 #include "libavutil/time.h"
 
+#include "internal.h"
 #include "url.h"
 
 #include <errno.h>
@@ -519,13 +520,14 @@ static int spacemap_init(URLContext *h, const uint8_t hash[HASH_SIZE])
         ret = set_once_uchar(&s->spacemap->hash[i], hash[i]);
         if (ret < 0) {
             av_log(h, AV_LOG_ERROR, "Shared cache spacemap hash mismatch!\n");
-            av_log(h, AV_LOG_ERROR, "  Expected hash: ");
-            for (int j = 0; j < 32; j++)
-                av_log(h, AV_LOG_ERROR, "%02X", hash[j]);
-            av_log(h, AV_LOG_ERROR, "\n  Got      hash: ");
-            for (int j = 0; j < 32; j++)
-                av_log(h, AV_LOG_ERROR, "%02X", atomic_load(&s->spacemap->hash[j]));
-            av_log(h, AV_LOG_ERROR, "\n");
+            char hash_hex[2 * HASH_SIZE + 1];
+            ff_data_to_hex(hash_hex, hash, HASH_SIZE, 0);
+            av_log(h, AV_LOG_ERROR, "  Expected hash: %s\n", hash_hex);
+            uint8_t hash2[HASH_SIZE];
+            for (int j = 0; j < HASH_SIZE; ++j)
+                hash2[j] = atomic_load_explicit(&s->spacemap->hash[j], memory_order_relaxed);
+            ff_data_to_hex(hash_hex, hash2, HASH_SIZE, 0);
+            av_log(h, AV_LOG_ERROR, "  Got      hash: %s\n", hash_hex);
             return ret;
         }
     }
-- 
2.52.0


>From 17670f87a5ddb138d03376671cb995b242cc7a8d Mon Sep 17 00:00:00 2001
From: Andreas Rheinhardt <[email protected]>
Date: Mon, 17 Aug 2026 04:13:26 +0200
Subject: [PATCH 2/4] avformat/ape: Don't log incomplete lines

Incomplete lines (without \n) may be torn apart by av_log()s
from other threads. So log them once. Also use ff_data_to_hex()
for the data->hex conversion.

Signed-off-by: Andreas Rheinhardt <[email protected]>
---
 libavformat/ape.c | 7 +++----
 1 file changed, 3 insertions(+), 4 deletions(-)

diff --git a/libavformat/ape.c b/libavformat/ape.c
index d2fd62902c..3bf359cb1f 100644
--- a/libavformat/ape.c
+++ b/libavformat/ape.c
@@ -107,10 +107,9 @@ static void ape_dumpinfo(AVFormatContext * s, APEContext * ape_ctx)
     av_log(s, AV_LOG_DEBUG, "audiodatalength      = %"PRIu32"\n", ape_ctx->audiodatalength);
     av_log(s, AV_LOG_DEBUG, "audiodatalength_high = %"PRIu32"\n", ape_ctx->audiodatalength_high);
     av_log(s, AV_LOG_DEBUG, "wavtaillength        = %"PRIu32"\n", ape_ctx->wavtaillength);
-    av_log(s, AV_LOG_DEBUG, "md5                  = ");
-    for (i = 0; i < 16; i++)
-         av_log(s, AV_LOG_DEBUG, "%02x", ape_ctx->md5[i]);
-    av_log(s, AV_LOG_DEBUG, "\n");
+    char md5_hex[sizeof(ape_ctx->md5) * 2 + 1];
+    ff_data_to_hex(md5_hex, ape_ctx->md5, sizeof(ape_ctx->md5), 1);
+    av_log(s, AV_LOG_DEBUG, "md5                  = %s\n", md5_hex);
 
     av_log(s, AV_LOG_DEBUG, "\nHeader Block:\n\n");
 
-- 
2.52.0


>From ffe22e37364e4010cf8238188a826f63d57b1e9e Mon Sep 17 00:00:00 2001
From: Andreas Rheinhardt <[email protected]>
Date: Mon, 17 Aug 2026 12:03:20 +0200
Subject: [PATCH 3/4] avformat/utils: Make ff_data_to_hex() usable with sizes >
 INT_MAX/2

It uses an int size field, so it should support the whole range.
Notice that no current caller could ever have been affected by this.

Signed-off-by: Andreas Rheinhardt <[email protected]>
---
 libavformat/utils.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/libavformat/utils.c b/libavformat/utils.c
index cb0ae7444e..dabd958397 100644
--- a/libavformat/utils.c
+++ b/libavformat/utils.c
@@ -473,11 +473,12 @@ char *ff_data_to_hex(char *buff, const uint8_t *src, int s, int lowercase)
                                            'c', 'd', 'e', 'f' };
     const char *hex_table = lowercase ? hex_table_lc : hex_table_uc;
 
-    for (int i = 0; i < s; i++) {
+    av_assume(s >= 0);
+    for (unsigned i = 0; i < s; i++) {
         buff[i * 2]     = hex_table[src[i] >> 4];
         buff[i * 2 + 1] = hex_table[src[i] & 0xF];
     }
-    buff[2 * s] = '\0';
+    buff[2U * s] = '\0';
 
     return buff;
 }
-- 
2.52.0


>From 7228890b4192a67c5e4a593cde06b4f4a378ff0e Mon Sep 17 00:00:00 2001
From: Andreas Rheinhardt <[email protected]>
Date: Mon, 17 Aug 2026 12:34:57 +0200
Subject: [PATCH 4/4] avformat/smoothstreamingenc: Use ff_data_to_hex() where
 advantageous

Signed-off-by: Andreas Rheinhardt <[email protected]>
---
 libavformat/smoothstreamingenc.c | 7 +++----
 1 file changed, 3 insertions(+), 4 deletions(-)

diff --git a/libavformat/smoothstreamingenc.c b/libavformat/smoothstreamingenc.c
index 3a4c1e0413..118761bfc0 100644
--- a/libavformat/smoothstreamingenc.c
+++ b/libavformat/smoothstreamingenc.c
@@ -142,7 +142,7 @@ static void get_private_data(OutputStream *os)
     AVCodecParameters *par = os->ctx->streams[0]->codecpar;
     uint8_t *ptr = par->extradata;
     int size = par->extradata_size;
-    int i;
+
     if (par->codec_id == AV_CODEC_ID_H264) {
         ff_avc_write_annexb_extradata(ptr, &ptr, &size);
         if (!ptr)
@@ -150,11 +150,10 @@ static void get_private_data(OutputStream *os)
     }
     if (!ptr)
         return;
-    os->private_str = av_mallocz(2*size + 1);
+    os->private_str = av_malloc(2U*size + 1);
     if (!os->private_str)
         goto fail;
-    for (i = 0; i < size; i++)
-        snprintf(&os->private_str[2*i], 3, "%02x", ptr[i]);
+    ff_data_to_hex(os->private_str, ptr, size, 1);
 fail:
     if (ptr != par->extradata)
         av_free(ptr);
-- 
2.52.0

_______________________________________________
ffmpeg-devel mailing list -- [email protected]
To unsubscribe send an email to [email protected]
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.