Skip to content

fix: potential crash caused by dlopen different gtk libraries - #33650

Merged
zcbenz merged 1 commit into
mainfrom
robo/fix_gtk_loading
Apr 18, 2022
Merged

fix: potential crash caused by dlopen different gtk libraries#33650
zcbenz merged 1 commit into
mainfrom
robo/fix_gtk_loading

Conversation

@deepak1556

@deepak1556 deepak1556 commented Apr 7, 2022

Copy link
Copy Markdown
Member

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 recently 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
Copy Markdown
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

deepak1556 commented Apr 7, 2022

Copy link
Copy Markdown
Member Author

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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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.

Comment thread shell/browser/ui/electron_gtk.sigs
Subject: Make gtk::GetLibGtk public

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

Copy link
Copy Markdown
Contributor

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
Copy Markdown
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.

Comment thread shell/browser/electron_browser_main_parts.cc
@electron-cation electron-cation Bot removed the new-pr 🌱 PR opened recently 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

release-clerk Bot commented Apr 18, 2022

Copy link
Copy Markdown

Release Notes Persisted

fix crash when opening gtk file dialogs due to mismatched versions

@trop

trop Bot commented Apr 18, 2022

Copy link
Copy Markdown
Contributor

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

@trop

trop Bot commented Apr 18, 2022

Copy link
Copy Markdown
Contributor

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

@trop

trop Bot commented Apr 18, 2022

Copy link
Copy Markdown
Contributor

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

trop Bot commented Jun 28, 2022

Copy link
Copy Markdown
Contributor

@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.

4 participants