Gentoo Websites Logo
Go to: Gentoo Home Documentation Forums Lists Bugs Planet Store Wiki Get Gentoo!
Bug 915384 - media-video/ffmpeg-4.4.4-r4: Crash when decoding AAC files with unset CPU_FLAGS_X86
Summary: media-video/ffmpeg-4.4.4-r4: Crash when decoding AAC files with unset CPU_FLA...
Status: IN_PROGRESS
Alias: None
Product: Gentoo Linux
Classification: Unclassified
Component: Current packages (show other bugs)
Hardware: AMD64 Linux
: Normal critical
Assignee: Gentoo Media-video project
URL:
Whiteboard:
Keywords:
: 918964 (view as bug list)
Depends on: 926151
Blocks: gcc-13
  Show dependency tree
 
Reported: 2023-10-08 14:27 UTC by realmariomario456
Modified: 2024-10-21 09:27 UTC (History)
5 users (show)

See Also:
Package list:
Runtime testing required: ---


Attachments
Backtrace (backtrace.log%0A,9.28 KB, text/plain)
2023-10-08 14:27 UTC, realmariomario456
Details
emerge --info (debug make.conf) (emerge-info-debug.txt,6.93 KB, text/plain)
2023-10-08 14:27 UTC, realmariomario456
Details
emerge --info (standard make.conf) (emerge-info.txt,6.89 KB, text/plain)
2023-10-08 14:28 UTC, realmariomario456
Details
strace (strace.log,159.79 KB, text/x-log)
2023-10-08 14:28 UTC, realmariomario456
Details
emerge -pv and emege --info for ffmpeg (ffmpeg_emerge_pv_info.txt,10.69 KB, text/plain)
2023-12-22 13:59 UTC, publiccontact2020
Details
emerge --info ffmpeg (emerge --info ffmpeg.txt,8.47 KB, text/plain)
2024-10-20 21:10 UTC, Albert
Details

Note You need to log in before you can comment on or make changes to this bug.
Description realmariomario456 2023-10-08 14:27:19 UTC
Created attachment 872336 [details]
Backtrace

This wasn't happening to me before, but now when FFmpeg tries to decode AAC (always with the FFmpeg command-line tool, most of the time with Audacity) it results in a crash. I've attached a full backtrace, strace and two emerge --infos (one is for my debugging make.conf, the other is for my standard make.conf) in this bug report. I assure this bug happens with both of my make.confs.
Comment 1 realmariomario456 2023-10-08 14:27:45 UTC
Created attachment 872337 [details]
emerge --info (debug make.conf)
Comment 2 realmariomario456 2023-10-08 14:28:08 UTC
Created attachment 872338 [details]
emerge --info (standard make.conf)
Comment 3 realmariomario456 2023-10-08 14:28:29 UTC
Created attachment 872339 [details]
strace
Comment 4 Sam James archtester Gentoo Infrastructure gentoo-dev Security 2023-10-09 00:55:44 UTC
Thanks.

We've seen this come up a few times recently.

My guess is the reason it's happening (more) now is gcc 13 being recently stabled.

It seems to be related to a mismatch between CPU_FLAGS_X86 and CFLAGS -march. Someone gave us Valgrind output before and it looked fairly clearly like an alignment problem.

For a workaround: please set CPU_FLAGS_X86 per app-portage/cpuid2cpuflags output.
Comment 5 Paul Zander 2023-10-09 08:37:53 UTC
From your emerge --info:
> CPU_FLAGS_X86="mmx mmxext sse sse2"
So that's the immediate cause.
Comment 6 realmariomario456 2023-10-25 20:09:08 UTC
(In reply to Sam James from comment #4)
> Thanks.
> 
> We've seen this come up a few times recently.
> 
> My guess is the reason it's happening (more) now is gcc 13 being recently
> stabled.
> 
> It seems to be related to a mismatch between CPU_FLAGS_X86 and CFLAGS
> -march. Someone gave us Valgrind output before and it looked fairly clearly
> like an alignment problem.
> 
> For a workaround: please set CPU_FLAGS_X86 per app-portage/cpuid2cpuflags
> output.

(In reply to Paul Zander from comment #5)
> From your emerge --info:
> > CPU_FLAGS_X86="mmx mmxext sse sse2"
> So that's the immediate cause.

Sorry for the late reply, I wasn't bothered to se CPU_FLAGS_X86 until now. But I've set it and the crash went away. This seems to prove that the crash is ebuild or GCC 13-related.
Comment 7 Matthias Hanft 2023-10-29 16:48:45 UTC
Can confirm a) the error and b) the workaround.

With gcc 12, everything runs fine - just like that.

With gcc 13 and just the usual

CFLAGS="-march=native -O2 -pipe"
CXXFLAGS="${CFLAGS}"
MAKEOPTS="-j2"
CHOST="x86_64-pc-linux-gnu"

I get

Oct 29 11:16:08 home01 kernel: traps: minidlnad[11961] general protection fault ip:7f44fcc1e2ea sp:7f44fbf48e20 error:0 in 
libavcodec.so.60.3.100[7f44fcbb2000+73b000]

and

Oct 29 17:02:12 home01 kernel: traps: ffmpeg[25236] general protection fault ip:7f349ddb12ea sp:7fff1726b400 error:0 in libavcodec.so.60.3.100[7f349dd45000+73b000]

With gcc 13 and additional

CPU_FLAGS_X86="aes avx avx2 f16c fma3 mmx mmxext pclmul popcnt rdrand sse sse2 sse3 sse4_1 sse4_2 ssse3"

(the output of cpuid2cpuflags), everything runs fine with gcc 13, too.

Here are the cpu_flags differences (equery u ffmpeg):

 U I
 - - cpu_flags_x86_3dnow    : Use the 3DNow! instruction set
 - - cpu_flags_x86_3dnowext : Use the Enhanced 3DNow! instruction set
 + - cpu_flags_x86_aes      : Enable support for Intel's AES instruction set (AES-NI)
 + - cpu_flags_x86_avx      : Adds support for Advanced Vector Extensions instructions
 + - cpu_flags_x86_avx2     : Adds support for Advanced Vector Extensions 2 instructions
 + - cpu_flags_x86_fma3     : Use the Fused Multiply Add 3 instruction set ([fma] in cpuinfo)
 - - cpu_flags_x86_fma4     : Use the Fused Multiply Add 4 instruction set
 + + cpu_flags_x86_mmx      : Use the MMX instruction set
 + + cpu_flags_x86_mmxext   : Use the Extended MMX instruction set (a subset of SSE) ([mmxext] or
                              [sse] in cpuinfo)
 + + cpu_flags_x86_sse      : Use the SSE instruction set
 + + cpu_flags_x86_sse2     : Use the SSE2 instruction set
 + - cpu_flags_x86_sse3     : Use the SSE3 instruction set ([pni] in cpuinfo, NOT ssse3)
 + - cpu_flags_x86_sse4_1   : Enable SSE4.1 instruction support
 + - cpu_flags_x86_sse4_2   : Enable SSE4.2 instruction support
 + - cpu_flags_x86_ssse3    : Use the SSSE3 instruction set (NOT sse3/pni)
 - - cpu_flags_x86_xop      : Enable the XOP instruction set

(column "I" is the standard installation without CPU_FLAGS_X86)

Thank you for the workaround, now I can delete gcc 12.
Comment 9 Paul Zander 2023-12-18 12:03:29 UTC
*** Bug 918964 has been marked as a duplicate of this bug. ***
Comment 10 publiccontact2020 2023-12-19 15:59:56 UTC Comment hidden (obsolete)
Comment 11 Paul Zander 2023-12-19 21:14:50 UTC Comment hidden (obsolete)
Comment 12 publiccontact2020 2023-12-20 16:58:49 UTC Comment hidden (obsolete)
Comment 13 Paul Zander 2023-12-21 15:10:32 UTC
Follow https://wiki.gentoo.org/wiki/CPU_FLAGS_*#Invocation.

Putting `CPU_FLAGS_X86=` in make.conf is the old method that still works but often leads to confusion.

Otherwise join #gentoo on irc and get help there.
Comment 14 publiccontact2020 2023-12-21 17:28:45 UTC Comment hidden (obsolete)
Comment 15 Paul Zander 2023-12-21 18:22:47 UTC Comment hidden (obsolete)
Comment 16 publiccontact2020 2023-12-22 13:59:16 UTC Comment hidden (obsolete)
Comment 17 Sam James archtester Gentoo Infrastructure gentoo-dev Security 2023-12-22 14:31:57 UTC Comment hidden (obsolete)
Comment 18 Larry the Git Cow gentoo-dev 2024-02-29 05:44:48 UTC
The bug has been referenced in the following commit(s):

https://gitweb.gentoo.org/repo/gentoo.git/commit/?id=4e4da320675b49841b4e7f477a6efe3c0413f674

commit 4e4da320675b49841b4e7f477a6efe3c0413f674
Author:     Sam James <sam@gentoo.org>
AuthorDate: 2024-02-29 05:42:04 +0000
Commit:     Sam James <sam@gentoo.org>
CommitDate: 2024-02-29 05:44:22 +0000

    media-video/ffmpeg: fix crash when CPU_FLAGS_x86 and CFLAGS disagree
    
    When CPU_FLAGS_X86 was set to the default for amd64 and CFLAGS was higher
    with e.g. -march=native including AVX, we could get crashes because we disable
    intrinsics which would otherwise adjust the alignment ffmpeg requests.
    
    Backport an upstream patch for more sensible behaviour.
    
    Note that the upstream patch doesn't apply to 4.4.x but I haven't tried
    to backport it manually. Someone is welcome to, but 4.4.x should really be
    on its way out by now.
    
    Bug: https://trac.ffmpeg.org/ticket/10549
    Bug: https://bugs.gentoo.org/915384
    Signed-off-by: Sam James <sam@gentoo.org>

 media-video/ffmpeg/ffmpeg-6.0.1-r3.ebuild          | 607 ++++++++++++++++++++
 media-video/ffmpeg/ffmpeg-6.1.1-r4.ebuild          | 614 +++++++++++++++++++++
 .../ffmpeg/files/ffmpeg-6.0.1-alignment.patch      | 114 ++++
 3 files changed, 1335 insertions(+)
Comment 19 Sam James archtester Gentoo Infrastructure gentoo-dev Security 2024-02-29 05:45:09 UTC
I'll leave this open for a little bit for visibility and in case anyone wants to do the 4.4.x backport.
Comment 20 Albert 2024-10-20 21:10:19 UTC
Created attachment 906471 [details]
emerge --info ffmpeg
Comment 21 Albert 2024-10-20 21:21:40 UTC
I am getting very similar issue with ffmpeg 6.1.2 compiled with GCC-14.2.1
CPU_FLAGS_X86 are set correctly as I understand

Failed command:
ffmpeg -hide_banner -hwaccel auto -loglevel error -i demo.mp4 -pix_fmt rgb24 temp/demo/%04d.png
Segmentation fault (core dumped)

Output of cpuid2cpuflags:
CPU_FLAGS_X86: aes avx avx2 f16c fma3 mmx mmxext pclmul popcnt rdrand sse sse2 sse3 sse4_1 sse4_2 ssse3

emerge --info ffmpeg:
https://bugs.gentoo.org/attachment.cgi?id=906471

dmesg:
[  730.867908] av:h264:df1[32931]: segfault at 0 ip 00007f6def75883e sp 00007f6dc7ffd750 error 4 in libavcodec.so.60.31.102[68b83e,7f6def0db000+804000] likely on CPU 5 (core 5, socket 0)
[  730.867918] Code: 41 5d 41 5e c3 0f 1f 80 00 00 00 00 f3 0f 1e fa 55 48 89 e5 41 57 49 89 d7 41 56 41 55 4d 89 c5 41 54 49 89 f4 53 48 83 ec 28 <48> 8b 1a 48 89 7c 24 08 48 89 4c 24 18 48 83 3b 00 0f 84 33 04 00
Comment 22 Albert 2024-10-20 21:22:21 UTC Comment hidden (obsolete)
Comment 23 Sam James archtester Gentoo Infrastructure gentoo-dev Security 2024-10-21 09:27:14 UTC
Can you file a separate bug please? I suspect it might be different.