fix: resolve crashes caused by using the ffmpeg library#580
Open
julee wants to merge 1 commit intoIENT:developfrom
Open
fix: resolve crashes caused by using the ffmpeg library#580julee wants to merge 1 commit intoIENT:developfrom
julee wants to merge 1 commit intoIENT:developfrom
Conversation
- Addressed issue where repeated reloading of the ffmpeg library led to crashes. Previously, each component attempted to load the ffmpeg library and executed an unload before loading, causing other components to retain stale function addresses if the library was reloaded at a different address. This issue was particularly prevalent on macOS. - Fixed undefined behavior due to incorrect size assumption of std::function objects. On certain platforms like arm64 macOS, sizeof(std::function<void()>) is 32, not the same as a pointer size. This discrepancy led to undefined behavior when forcibly casting. This fix ensures that the library is loaded only once per process and corrects the handling of std::function objects to prevent crashes.
Member
|
Hi! Thanks for the report. I have not heard of this undefined behavior so far. Do you have a link to this? Maybe an article or a bugreport? |
Author
|
The core reason for the crash is that after unloading the dynamic library, the original symbol addresses are still being used. This is not undefined behavior, but a clear bug! consider code: //compoent A:
QLibrary lib;
lib.setFileName(libAVCodecPath);
lib.unload(); //call by unloadAllLibraries
lib.load();
void *fucntionPtr1 = lib.resolve(symbolNameSuchAsAVCodecOpen);
//compoent B:
QLibrary lib;
lib.setFileName(libAVCodecPath);
// as shared library loading is global for one process, so here, lib.unload() will cause libAVCodecPath loaded in compoent A unload!
lib.unload(); //call by unloadAllLibraries
lib.load();
void *fucntionPtr2 = lib.resolve(symbolNameSuchAsAVCodecOpen); // this address may be different with fucntionPtr1
application go on run:
compoentA.runXXXUse_fucntionPtr1(); // go on use: functionPtr1, but this address is invalid,
|
Author
|
Can you continue to evaluate this issue? |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This fix ensures that the library is loaded only once per process and corrects the handling of std::function objects to prevent crashes.