[vlc-commits] [Git][videolan/vlc][master] 2 commits: avcodec: check the channel mask matches the channel count

Steve Lhomme (@robUx4) gitlab at videolan.org
Thu Jul 23 08:56:00 UTC 2026



Steve Lhomme pushed to branch master at VideoLAN / VLC


Commits:
0bdf7108 by Steve Lhomme at 2026-07-23T08:13:07+00:00
avcodec: check the channel mask matches the channel count

>From the libavutil documentation [^1]:

> when a channel layout using a bitmask is constructed or modified manually
> (i.e. not using any of the av_channel_layout_* functions), the code doing
> it must ensure that the number of set bits is equal to nb_channels.

[^1]: https://code.ffmpeg.org/FFmpeg/FFmpeg/src/commit/9917308cc209a885c6870f0345905104c6ea8799/libavutil/channel_layout.h#L337

- - - - -
63ca0384 by Steve Lhomme at 2026-07-23T08:13:07+00:00
avcodec: do not use audio channels that don't map in VLC

pi_order_src should only contain valid AOUT_CHAN_xxx values, limited to AOUT_CHAN_MAX.
We should not keep adding channels just because they are defined in the channel mask.

Fixes #29634

- - - - -


1 changed file:

- modules/codec/avcodec/audio.c


Changes:

=====================================
modules/codec/avcodec/audio.c
=====================================
@@ -38,6 +38,8 @@
 #include "avcodec.h"
 #include "../../demux/xiph.h"
 
+#include <stdbit.h>
+
 #include <libavcodec/avcodec.h>
 #include <libavutil/mem.h>
 
@@ -672,7 +674,7 @@ static void SetupOutputFormat( decoder_t *p_dec, bool b_trust )
     if( channel_layout_mask )
     {
         uint32_t* pi_order_src = calloc(channel_count,sizeof(uint32_t));
-        
+
         if( unlikely(pi_order_src == NULL) )
         {
             p_dec->fmt_out.audio.i_physical_channels = 0;
@@ -682,10 +684,12 @@ static void SetupOutputFormat( decoder_t *p_dec, bool b_trust )
             return;
         }
 
+        assert(stdc_count_ones(channel_layout_mask) == (unsigned)channel_count);
+
         for( unsigned i = 0; pi_channels_map[i][0]
          && i_channels_src < channel_count; i++ )
         {
-            if( channel_layout_mask & pi_channels_map[i][0] )
+            if( (channel_layout_mask & pi_channels_map[i][0]) && pi_channels_map[i][1] )
                 pi_order_src[i_channels_src++] = pi_channels_map[i][1];
         }
 
@@ -727,4 +731,3 @@ static void SetupOutputFormat( decoder_t *p_dec, bool b_trust )
 
     aout_FormatPrepare( &p_dec->fmt_out.audio );
 }
-



View it on GitLab: https://code.videolan.org/videolan/vlc/-/compare/edb48c59aaf3658c099d4ed41685a07dd0d428ee...63ca0384c36104b9a8368d40f73ee4d46b9167fb

-- 
View it on GitLab: https://code.videolan.org/videolan/vlc/-/compare/edb48c59aaf3658c099d4ed41685a07dd0d428ee...63ca0384c36104b9a8368d40f73ee4d46b9167fb
You're receiving this email because of your account on code.videolan.org. Manage all notifications: https://code.videolan.org/-/profile/notifications | Help: https://code.videolan.org/help




More information about the vlc-commits mailing list