PR #23413 opened by Daniel Verkamp (drv) URL: https://code.ffmpeg.org/FFmpeg/FFmpeg/pulls/23413 Patch URL: https://code.ffmpeg.org/FFmpeg/FFmpeg/pulls/23413.patch
When writing the trailer for a RF64 WAV file, the ds64 chunk's 64-bit version of the data chunk size incorrectly included the padding byte that may have been added by ff_end_tag() for the data chunk. Fix this by calculating the data chunk size before calling ff_end_tag(). The data chunk padding byte is only needed when the data is not already a multiple of two bytes in length, which is fairly rare, requiring something like mono 8-bit or 24-bit PCM with an odd number of samples to trigger (and only with -rf64 auto or -rf64 always, neither of which is enabled by default), so this bug is not likely to have affected many real-world files. >From ced98f2f1da320db0a49df546288498db4707d46 Mon Sep 17 00:00:00 2001 From: Daniel Verkamp <[email protected]> Date: Tue, 9 Jun 2026 00:01:59 -0700 Subject: [PATCH] avformat/wavenc: Don't count padding in rf64 data chunk size When writing the trailer for a RF64 WAV file, the ds64 chunk's 64-bit version of the data chunk size incorrectly included the padding byte that may have been added by ff_end_tag() for the data chunk. Fix this by calculating the data chunk size before calling ff_end_tag(). The data chunk padding byte is only needed when the data is not already a multiple of two bytes in length, which is fairly rare, requiring something like mono 8-bit or 24-bit PCM with an odd number of samples to trigger (and only with -rf64 auto or -rf64 always, neither of which is enabled by default), so this bug is not likely to have affected many real-world files. Signed-off-by: Daniel Verkamp <[email protected]> --- libavformat/wavenc.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/libavformat/wavenc.c b/libavformat/wavenc.c index 01fffaafe5..a8debf8faa 100644 --- a/libavformat/wavenc.c +++ b/libavformat/wavenc.c @@ -426,7 +426,8 @@ static int wav_write_trailer(AVFormatContext *s) int ret = 0; if (s->pb->seekable & AVIO_SEEKABLE_NORMAL) { - if (wav->write_peak != PEAK_ONLY && avio_tell(pb) - wav->data < UINT32_MAX) { + data_size = avio_tell(pb) - wav->data; + if (wav->write_peak != PEAK_ONLY && data_size < UINT32_MAX) { ff_end_tag(pb, wav->data); } @@ -436,7 +437,6 @@ static int wav_write_trailer(AVFormatContext *s) /* update file size */ file_size = avio_tell(pb); - data_size = file_size - wav->data; if (wav->rf64 == RF64_ALWAYS || (wav->rf64 == RF64_AUTO && file_size - 8 > UINT32_MAX)) { rf64 = 1; } else if (file_size - 8 <= UINT32_MAX) { -- 2.52.0 _______________________________________________ ffmpeg-devel mailing list -- [email protected] To unsubscribe send an email to [email protected]
