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: potential crash caused by dlopen different gtk libraries #33650

Merged
merged 1 commit into from Apr 18, 2022

Conversation

deepak1556
Copy link
Member

@deepak1556 deepak1556 commented Apr 7, 2022

Description of Change

#19159 refactored file dialog implementation that relies requiring gtk library at runtime, around the same time chromium has been refactoring itself to also require gtk at runtime https://bugs.chromium.org/p/chromium/issues/detail?id=1192861

Since chromium already loads the required gtk library into the process on startup, the file dialog implementation should just get a handle to the loaded library and perform operations on it, the current implementation can lead to situations in classic snaps where two different version gtk libraries can get loaded into the same process triggering a crash, refs microsoft/vscode#146584 (comment)

NB: There is no functionality change in this PR, simplifies library loading following upstream changes and fixes potential crash alongside.

/cc @tristan957

Checklist

Release Notes

Notes: fix crash when opening gtk file dialogs due to mismatched versions

@deepak1556 deepak1556 requested review from a team as code owners April 7, 2022 12:12
@electron-cation electron-cation bot added the new-pr 🌱 PR opened in the last 24 hours label Apr 7, 2022
@deepak1556 deepak1556 requested review from ckerr and zcbenz April 7, 2022 12:12
@deepak1556 deepak1556 added semver/patch backwards-compatible bug fixes target/16-x-y labels Apr 7, 2022
@tristan957
Copy link
Contributor

Hi @deepak1556. Thanks for tracking down the source of the issue. With your PR, I am a little confused how any of the gtk_file_chooser_native_* methods work because it is possible that those symbols don't exist.

Where is the definition of electron::IsElectron_gtkInitialized()?

@deepak1556
Copy link
Member Author

deepak1556 commented Apr 7, 2022

electron_gtk_stubs.cc is responsible for loading the symbols and providing utilities to check if the required symbols are loaded, this file is generated during compile time. An example can be seen with upstream's stub file that gets generated for https://source.chromium.org/chromium/chromium/src/+/main:ui/gtk/gtk.sig, if the symbol is not present it will just call the utility function (example) is provided as part of logging_function in the Build.gn file. In our case, we provide a noop logger which allows for symbol load failures.

@tristan957
Copy link
Contributor

Ok cool. Thanks for the background. This PR sounds like a good solution then. I wonder if Flatpak has the same issue.

@deepak1556
Copy link
Member Author

Not familiar with flaptak, but if it does not search for libraries from the host then worst case would be it fails to load the required gtk version with the symbols and end up calling the legacy dialog fallback. I think only classical snaps can run into this crash edge case.

@tristan957
Copy link
Contributor

I am not at all familiar with the confinement of snap vs classical snap vs flatpak. As you said, I guess classical snap is the outlier here and it is really weird to have to program around this packaging format when seemingly it would work for snap and flatpak.

Subject: Make gtk::GetLibGtk public

Allows embedders to get a handle to the gtk library
already loaded in the process.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should this be upstreamed?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I can give it an attempt.

@electron-cation electron-cation bot removed the new-pr 🌱 PR opened in the last 24 hours label Apr 8, 2022
@zcbenz zcbenz merged commit 37b7e34 into main Apr 18, 2022
@zcbenz zcbenz deleted the robo/fix_gtk_loading branch April 18, 2022 04:24
@release-clerk
Copy link

release-clerk bot commented Apr 18, 2022

Release Notes Persisted

fix crash when opening gtk file dialogs due to mismatched versions

@trop
Copy link
Contributor

trop bot commented Apr 18, 2022

I was unable to backport this PR to "16-x-y" cleanly;
you will need to perform this backport manually.

@trop
Copy link
Contributor

trop bot commented Apr 18, 2022

I was unable to backport this PR to "17-x-y" cleanly;
you will need to perform this backport manually.

@trop
Copy link
Contributor

trop bot commented Apr 18, 2022

I have automatically backported this PR to "19-x-y", please check out #33813

bavulapati pushed a commit to bavulapati/electron that referenced this pull request Apr 29, 2022
@trop
Copy link
Contributor

trop bot commented Jun 28, 2022

@miniak has manually backported this PR to "17-x-y", please check out #34774

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
semver/patch backwards-compatible bug fixes
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants