PR #23525 opened by add-uos-ffmpeg
URL: https://code.ffmpeg.org/FFmpeg/FFmpeg/pulls/23525
Patch URL: https://code.ffmpeg.org/FFmpeg/FFmpeg/pulls/23525.patch

ff_codec_id_to_pulse_format() returns PA_SAMPLE_INVALID for
unsupported codecs (e.g. AAC, FLAC, Opus). Without validation,
the invalid format propagates to pa_frame_size() and other PA
calls, causing assertion failures or division-by-zero.

Add pa_sample_spec_valid() check, matching the existing guard
in pulse_audio_enc.c.

Signed-off-by: zhanghongyuan <[email protected]>

# Summary of changes

Add pa_sample_spec_valid() check in pulse_read_header() to reject unsupported 
codecs with a clean error instead of crashing.

**1. unsupport acodec  may crush**

`$ ffmpeg -hide_banner -loglevel verbose -f pulse -acodec aac -i default -t 0.5 
-f null - 2>&1`

    Assertion 'pa_sample_spec_valid(spec)' failed at ../src/pulse/sample.c:67, 
function pa_frame_size(). Aborting.
    已放弃(核心已转储)

`$ coredumpctl list | grep ffmpeg`

    Hint: You are currently not seeing messages from other users and the system.
          Users in groups 'adm', 'systemd-journal' can see all messages.
          Pass -q to turn off this notice.
    Thu 2026-06-18 10:54:58 CST  113874 1000 1000 SIGABRT present  
/usr/bin/ffmpeg                                                              
10.0M
    Thu 2026-06-18 10:59:41 CST  115966 1000 1000 SIGABRT present  
/usr/bin/ffmpeg                                                              
10.0M
    Thu 2026-06-18 11:25:34 CST  126047 1000 1000 SIGABRT present  
/usr/bin/ffmpeg                                                              
10.0M
    Thu 2026-06-18 13:28:16 CST   18830 1000 1000 SIGABRT present  
/usr/bin/ffmpeg                                                              
10.0M
    Thu 2026-06-18 13:29:30 CST   18937 1000 1000 SIGABRT present  
/usr/bin/ffmpeg                                                              
10.0M
    Thu 2026-06-18 13:50:29 CST   24446 1000 1000 SIGABRT present  
/usr/bin/ffmpeg                                                              
10.0M


**2. after fix**

`$ ffmpeg -hide_banner  -f pulse -acodec aac -i default -t 0.5 -f null - 2>&1`
    
    [in#0 @ 0x55bd82919a00] Invalid sample spec.
    [in#0 @ 0x55bd82919700] Error opening input: Invalid argument               
                                                                                
                                  
    Error opening input file default.                                           
                                                                                
                                  
    Error opening input files: Invalid argument                                 
                                                                                
                       
                                                                                
                                                                                
                                  
    Exiting with exit code -22                   

as same as 'pulse_audio_enc.c'

`$ ffmpeg -hide_banner -f lavfi -i anullsrc=r=48000:cl=stereo -acodec aac -t 
0.5 -f pulse -y default 2>&1`

     Input #0, lavfi, from 'anullsrc=r=48000:cl=stereo':
      Duration: N/A, start: 0.000000, bitrate: 768 kb/s
      Stream #0:0: Audio: pcm_u8, 48000 Hz, stereo, u8, 768 kb/s
    Stream mapping:
      Stream #0:0 -> #0:0 (pcm_u8 (native) -> aac (native))
    Press [q] to stop, [?] for help
    [PulseAudio outdev @ 0x55b7ad2c0880] Invalid sample spec.
    [out#0/pulse @ 0x55b7ad2c0500] Could not write header (incorrect codec 
parameters ?): Invalid argument
    [af#0:0 @ 0x55b7ad2c1500] Error sending frames to consumers: Invalid 
argument
    [af#0:0 @ 0x55b7ad2c1500] Task finished with error code: -22 (Invalid 
argument)
    [af#0:0 @ 0x55b7ad2c1500] Terminating thread with return code -22 (Invalid 
argument)
    [out#0/pulse @ 0x55b7ad2c0500] Nothing was written into output file, 
because at least one of its streams received no packets.
    size=       0KiB time=N/A bitrate=N/A speed=N/A elapsed=0:00:00.00    
    [aac @ 0x55b7ad2c0fc0] Qavg: nan
    Conversion failed!



From 98524b17a9fed0b1fc524457db2e9fa2f4073a1c Mon Sep 17 00:00:00 2001
From: zhanghongyuan <[email protected]>
Date: Thu, 18 Jun 2026 13:19:31 +0800
Subject: [PATCH] avdevice/pulse_audio_dec: validate sample spec before use

ff_codec_id_to_pulse_format() returns PA_SAMPLE_INVALID for
unsupported codecs (e.g. AAC, FLAC, Opus). Without validation,
the invalid format propagates to pa_frame_size() and other PA
calls, causing assertion failures or division-by-zero.

Add pa_sample_spec_valid() check, matching the existing guard
in pulse_audio_enc.c.

Signed-off-by: zhanghongyuan <[email protected]>
---
 libavdevice/pulse_audio_dec.c | 5 +++++
 1 file changed, 5 insertions(+)

diff --git a/libavdevice/pulse_audio_dec.c b/libavdevice/pulse_audio_dec.c
index 32be18e7dd..fe60d02b5d 100644
--- a/libavdevice/pulse_audio_dec.c
+++ b/libavdevice/pulse_audio_dec.c
@@ -156,6 +156,11 @@ static av_cold int pulse_read_header(AVFormatContext *s)
 
     pa_channel_map_init_extend(&cmap, pd->channels, PA_CHANNEL_MAP_WAVEEX);
 
+    if (!pa_sample_spec_valid(&ss)) {
+        av_log(s, AV_LOG_ERROR, "Invalid sample spec.\n");
+        return AVERROR(EINVAL);
+    }
+
     st = avformat_new_stream(s, NULL);
 
     if (!st) {
-- 
2.52.0

_______________________________________________
ffmpeg-devel mailing list -- [email protected]
To unsubscribe send an email to [email protected]

Reply via email to