Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix segfault when reading mp4 files #1078

Closed
wants to merge 20 commits into from
Closed

Fix segfault when reading mp4 files #1078

wants to merge 20 commits into from

Conversation

OxygenCobalt
Copy link

@OxygenCobalt OxygenCobalt commented Apr 18, 2021

Cmus will encounter a segmentation fault reading mp4/m4a/m4b if the shared libmp4v2 library is at v4.1.4+. This is because that release changed the MP4Read function from an overloaded method to a single method with a default argument of nullptr, causing cmus to segfault when it only specified one argument.

This PR fixes that by changing the function call to specify NULL as the second argument, which prevents cmus from segfaulting.

Fixes #1076.

Related: mp4v2/#47

Feel free to raise any concerns with this fix.

Fix a problem where any mp4/mpeg-4 file will cause cmus to segfault when read.
This was because of a recent change in `libmp4v2` that changed the MP4Read function from an overload with a filename/atomic callback to a C++ default argument with nullptr, which then caused a segfault when called without the second argument.
Clang possibly requires the MP4Read function to be cast for it to compile, so the MP4Read call has been changed to reflect that.
The #ifdef has also been reintroduced. Just in case.
Add a return statement to the casted MP4Read call.
Also remove the ifdef since it is not needed.
Add an __APPLE__ ifdef to the MP4Read call so that MacOS's libmp4v2 can
be called properly [apparently it doesn't have a second argument]. Not
sure how effective this is.
Forgot to close the ifdef. Whoops.
Quickly clean up some of the comments of this fix.
Turns out that libmp4v2 was actually updated on MacOS to add that new
second argument. This means that the build should pass. Oh well.
This reverts commit 0860527.
The CI didnt work, they still havent fixed this issue.
ip/mp4.c Outdated Show resolved Hide resolved
OxygenCobalt and others added 2 commits October 6, 2021 11:17
Use the MP4V2 version instead of the OS variant to determine whether to use the new API

Co-authored-by: Niko E. <nefthy@users.noreply.github.com>
Now that this MP4Read fix is practically finalized, make sure we properly document why we make this call.
@OxygenCobalt
Copy link
Author

OxygenCobalt commented Oct 6, 2021

Okay, that's an absolute joke.

At this point, we have three options:

  1. Use the #ifdef __APPLE__ band-aid, which will break if homebrew ever decides to switch to techsmith and is just stupid.
  2. Beg every package manager using the techsmith mp4v2 to instead use the abandoned upstream mp4v2. This is also stupid.
  3. Hard-fork techsmith or upstream mp4v2 for cmus, revert the API change, and then maintain it separately.

I'm in favor of 3. However, cmus is already in dire need of a maintainer, so adding an mp4v2 fork on top of that would make matters worse. If no action is taken I'll likely just drop this PR entirely since there really seems to be no good solution to this that doesn't involve a fork of some kind [a task that I'm really not ready for given that I'm juggling two other projects right now].

@nefthy
Copy link
Collaborator

nefthy commented Oct 6, 2021

Okay, that's an absolute joke.

At this point, we have three options:

  1. Use the #ifdef __APPLE__ band-aid, which will break if homebrew ever decides to switch to techsmith and is just stupid.

That is not a good Idea. Linux systems could also use the abandoned upstream.

  1. Beg every package manager using the techsmith mp4v2 to instead use the abandoned upstream mp4v2. This is also stupid.

What package managers do is not in under our control.

  1. Hard-fork techsmith or upstream mp4v2 for cmus, revert the API change, and then maintain it separately.

I don't think pulling mp4v2 into cmus is a good idea.

We should test at configure time which mp4v2 we have and do a #typedef.

gcc -x c -Wall -Wextra - <<EOF
#include <mp4v2/mp4v2.h>

int main() {
        MP4Read("/dev/null", NULL);
        return 1;
}
EOF
echo $?

gives a result of 1 on my system, which is not using the techsmith fork.

@OxygenCobalt
Copy link
Author

Hm. Good idea. I'll try to take a crack at it later.

@OxygenCobalt
Copy link
Author

Okay, I got blind-sighted by other projects and forgot about this PR, but now I'm actually going to try to add a configuration for this, like you suggested. Give me some time and I'll try to make this PR actually become workable.

Add a block to the configuration script that seems to adequately detect
for the techsmith fork. Basically, if we can't detect the header but
can still confirm that the library exists through try_link, we just
assume it's the techsmith fork since by default the busted header
won't compile.
@OxygenCobalt
Copy link
Author

I give up. I can't get the configure script working at all. For some reason the mere act of adding my fix causes the CI to repeatedly fail, continues trying to import mp4.h despite that not existing and that shouldn't occurring in the first place. I have no idea why. I have no idea how. I can only assume that this bug is unfixable at this point. I'm just going to switch to MPD since that seems to be actually maintained. Good luck to anyone else trying to tackle this mess.

@OxygenCobalt OxygenCobalt deleted the mp4-no-segfault branch January 8, 2022 20:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Segmentation fault when opening any m4a/m4b/mp4 file
2 participants