[vlc-commits] [Git][videolan/vlc][3.0.x] 4 commits: mkv: do not dereference unaligned pointer

Steve Lhomme (@robUx4) gitlab at videolan.org
Sun Mar 15 10:43:24 UTC 2026



Steve Lhomme pushed to branch 3.0.x at VideoLAN / VLC


Commits:
b7952c19 by Rémi Denis-Courmont at 2026-03-15T10:16:05+00:00
mkv: do not dereference unaligned pointer

(cherry picked from commit 37b8947693e5f9445944086a810d74d298e2847f)

- - - - -
ee027641 by Steve Lhomme at 2026-03-15T10:16:05+00:00
modules: use container_of to get the WAVEFORMATEXTENSIBLE from WAVEFORMATEX

(cherry picked from commit 1b86b2ffa583eb2f4cf83b94794695ba68396f86) (edited)
edited:
- in AVI the structure is stored in a different pointer

- - - - -
331e1597 by Steve Lhomme at 2026-03-15T10:16:05+00:00
wasapi: log the WAVEFORMATEX when there's an error

(cherry picked from commit 63b7a09e79e66133d64df4dfd9c3f970f75ce68d) (edited)
edited:
- VLC 3 doesn't have vlc_logger

- - - - -
51bad020 by Steve Lhomme at 2026-03-15T10:16:05+00:00
wasapi: verify the cbSize matches the WAVEFORMATEXTENSIBLE size

(cherry picked from commit 0921d77f5c9ab79a973d763c7c728bea737dc43c)

- - - - -


4 changed files:

- modules/access/wasapi.c
- modules/audio_output/wasapi.c
- modules/demux/avi/avi.c
- modules/demux/mkv/matroska_segment_parse.cpp


Changes:

=====================================
modules/access/wasapi.c
=====================================
@@ -130,8 +130,9 @@ static int vlc_FromWave(const WAVEFORMATEX *restrict wf,
 
     /* As per MSDN, IAudioClient::GetMixFormat() always uses this format. */
     assert(wf->wFormatTag == WAVE_FORMAT_EXTENSIBLE);
+    assert(wf->cbSize >= sizeof(WAVEFORMATEXTENSIBLE) - sizeof(WAVEFORMATEX));
 
-    const WAVEFORMATEXTENSIBLE *wfe = (void *)wf;
+    const WAVEFORMATEXTENSIBLE *wfe = container_of(wf, WAVEFORMATEXTENSIBLE, Format);
 
     fmt->i_physical_channels = 0;
     if (wfe->dwChannelMask & SPEAKER_FRONT_LEFT)


=====================================
modules/audio_output/wasapi.c
=====================================
@@ -390,15 +390,40 @@ static void vlc_ToWave(WAVEFORMATEXTENSIBLE *restrict wf,
             wf->dwChannelMask |= chans_in[i];
 }
 
+static void LogWaveFormat(vlc_object_t *o, const WAVEFORMATEX *restrict wf)
+{
+    msg_Dbg(o, "nChannels %d", wf->nChannels);
+    msg_Dbg(o, "wBitsPerSample %d", wf->wBitsPerSample);
+    msg_Dbg(o, "nAvgBytesPerSec %d", wf->nAvgBytesPerSec);
+    msg_Dbg(o, "nSamplesPerSec %d", wf->nSamplesPerSec);
+    msg_Dbg(o, "nBlockAlign %d", wf->nBlockAlign);
+    msg_Dbg(o, "cbSize %d", wf->cbSize);
+    msg_Dbg(o, "wFormatTag 0x%04X", wf->wFormatTag);
+
+    if (wf->wFormatTag == WAVE_FORMAT_EXTENSIBLE &&
+        wf->cbSize >= sizeof(WAVEFORMATEXTENSIBLE) - sizeof(WAVEFORMATEX))
+    {
+        const WAVEFORMATEXTENSIBLE *wfe = container_of(wf, WAVEFORMATEXTENSIBLE, Format);
+        if (IsEqualIID(&wfe->SubFormat, &KSDATAFORMAT_SUBTYPE_IEEE_FLOAT))
+            msg_Dbg(o, "SubFormat IEEE_FLOAT");
+        else if (IsEqualIID(&wfe->SubFormat, &KSDATAFORMAT_SUBTYPE_PCM))
+            msg_Dbg(o, "SubFormat PCM");
+        else
+            msg_Dbg(o, "SubFormat " GUID_FMT, GUID_PRINT(wfe->SubFormat));
+        msg_Dbg(o, "wValidBitsPerSample %d", wfe->Samples.wValidBitsPerSample);
+    }
+}
+
 static int vlc_FromWave(const WAVEFORMATEX *restrict wf,
                         audio_sample_format_t *restrict audio)
 {
     audio->i_rate = wf->nSamplesPerSec;
     audio->i_physical_channels = 0;
 
-    if (wf->wFormatTag == WAVE_FORMAT_EXTENSIBLE)
+    if (wf->wFormatTag == WAVE_FORMAT_EXTENSIBLE &&
+        wf->cbSize >= sizeof(WAVEFORMATEXTENSIBLE) - sizeof(WAVEFORMATEX))
     {
-        const WAVEFORMATEXTENSIBLE *wfe = (void *)wf;
+        const WAVEFORMATEXTENSIBLE *wfe = container_of(wf, WAVEFORMATEXTENSIBLE, Format);
 
         if (IsEqualIID(&wfe->SubFormat, &KSDATAFORMAT_SUBTYPE_IEEE_FLOAT))
         {
@@ -529,7 +554,11 @@ static HRESULT Start(aout_stream_t *s, audio_sample_format_t *restrict pfmt,
             /* Render Ambisonics on the native mix format */
             hr = IAudioClient_GetMixFormat(sys->client, &pwf_mix);
             if (FAILED(hr) || vlc_FromWave(pwf_mix, &fmt))
+            {
+                msg_Dbg(s, "failed to use mix format");
+                LogWaveFormat(VLC_OBJECT(s), pwf_mix);
                 vlc_ToWave(pwfe, &fmt); /* failed, fallback to default */
+            }
             else
                 pwf = pwf_mix;
 
@@ -575,8 +604,9 @@ static HRESULT Start(aout_stream_t *s, audio_sample_format_t *restrict pfmt,
         assert(pwf_closest != NULL);
         if (vlc_FromWave(pwf_closest, &fmt))
         {
+            msg_Err(s, "unsupported closest audio format");
+            LogWaveFormat(VLC_OBJECT(s), pwf_closest);
             CoTaskMemFree(pwf_closest);
-            msg_Err(s, "unsupported audio format");
             hr = E_INVALIDARG;
             goto error;
         }


=====================================
modules/demux/avi/avi.c
=====================================
@@ -536,7 +536,7 @@ static int Open( vlc_object_t * p_this )
                 if( p_wf->wFormatTag == WAVE_FORMAT_EXTENSIBLE &&
                     p_wf->cbSize >= sizeof(WAVEFORMATEXTENSIBLE) - sizeof(WAVEFORMATEX) )
                 {
-                    WAVEFORMATEXTENSIBLE *p_wfe = (WAVEFORMATEXTENSIBLE *)p_wf;
+                    WAVEFORMATEXTENSIBLE *p_wfe = container_of(p_wf, WAVEFORMATEXTENSIBLE, Format);
                     tk->fmt.i_codec = AVI_FourccGetCodec( AUDIO_ES, p_wfe->SubFormat.Data1 );
                 }
                 else


=====================================
modules/demux/mkv/matroska_segment_parse.cpp
=====================================
@@ -1661,8 +1661,10 @@ bool matroska_segment_c::TrackInit( mkv_track_t * p_tk )
                 if( p_wf->wFormatTag == WAVE_FORMAT_EXTENSIBLE &&
                     p_tk->i_extra_data >= sizeof(WAVEFORMATEXTENSIBLE) )
                 {
-                    WAVEFORMATEXTENSIBLE * p_wext = (WAVEFORMATEXTENSIBLE*) p_wf;
-                    sf_tag_to_fourcc( &p_wext->SubFormat,  &p_tk->fmt.i_codec, NULL);
+                    WAVEFORMATEXTENSIBLE *p_wext = container_of(p_wf, WAVEFORMATEXTENSIBLE, Format);
+                    GUID subFormat = p_wext->SubFormat;
+
+                    sf_tag_to_fourcc( &subFormat,  &p_tk->fmt.i_codec, NULL);
                     /* FIXME should we use Samples */
 
                     if( p_tk->fmt.audio.i_channels > 2 &&



View it on GitLab: https://code.videolan.org/videolan/vlc/-/compare/58f89d173ff698ac01d63f7c5136171c1b637f5e...51bad0205b4f232478dfa6e1dfa967412fedc55b

-- 
View it on GitLab: https://code.videolan.org/videolan/vlc/-/compare/58f89d173ff698ac01d63f7c5136171c1b637f5e...51bad0205b4f232478dfa6e1dfa967412fedc55b
You're receiving this email because of your account on code.videolan.org.


VideoLAN code repository instance


More information about the vlc-commits mailing list