-
Notifications
You must be signed in to change notification settings - Fork 263
[desktop_drop]: fix Deepin/UOS drop (dde-fileManager) by preferring URI targets #464
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
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -21,14 +21,50 @@ G_DEFINE_TYPE(DesktopDropPlugin, desktop_drop_plugin, g_object_get_type()) | |||||||||||||||||||||||||||||||||||||||||
| void on_drag_data_received(GtkWidget *widget, GdkDragContext *drag_context, | ||||||||||||||||||||||||||||||||||||||||||
| gint x, gint y, GtkSelectionData *sdata, guint info, | ||||||||||||||||||||||||||||||||||||||||||
| guint time, gpointer user_data) { | ||||||||||||||||||||||||||||||||||||||||||
| // When dragging from different file managers we may receive a plain string | ||||||||||||||||||||||||||||||||||||||||||
| // (e.g. "dde-fileManager") instead of real URIs. Use gtk_selection_data_get_uris | ||||||||||||||||||||||||||||||||||||||||||
| // which understands the "text/uri-list" format and returns an array of | ||||||||||||||||||||||||||||||||||||||||||
| // URI strings. Convert those to local filenames and join with newlines. | ||||||||||||||||||||||||||||||||||||||||||
| auto *channel = static_cast<FlMethodChannel *>(user_data); | ||||||||||||||||||||||||||||||||||||||||||
| auto *data = gtk_selection_data_get_data(sdata); | ||||||||||||||||||||||||||||||||||||||||||
| double point[] = {double(x), double(y)}; | ||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||
| gchar *text = nullptr; | ||||||||||||||||||||||||||||||||||||||||||
| gchar **uris = gtk_selection_data_get_uris(sdata); | ||||||||||||||||||||||||||||||||||||||||||
| if (uris) { | ||||||||||||||||||||||||||||||||||||||||||
| // build newline-separated list of file paths | ||||||||||||||||||||||||||||||||||||||||||
| GString *builder = g_string_new(NULL); | ||||||||||||||||||||||||||||||||||||||||||
| for (gchar **uri = uris; *uri; uri++) { | ||||||||||||||||||||||||||||||||||||||||||
| gchar *filename = g_filename_from_uri(*uri, nullptr, nullptr); | ||||||||||||||||||||||||||||||||||||||||||
| if (!filename) { | ||||||||||||||||||||||||||||||||||||||||||
| // if conversion failed, fall back to raw URI | ||||||||||||||||||||||||||||||||||||||||||
| filename = g_strdup(*uri); | ||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||
| if (builder->len > 0) { | ||||||||||||||||||||||||||||||||||||||||||
| g_string_append(builder, "\n"); | ||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||
| g_string_append(builder, filename); | ||||||||||||||||||||||||||||||||||||||||||
| g_free(filename); | ||||||||||||||||||||||||||||||||||||||||||
|
Comment on lines
+34
to
+46
|
||||||||||||||||||||||||||||||||||||||||||
| // build newline-separated list of file paths | |
| GString *builder = g_string_new(NULL); | |
| for (gchar **uri = uris; *uri; uri++) { | |
| gchar *filename = g_filename_from_uri(*uri, nullptr, nullptr); | |
| if (!filename) { | |
| // if conversion failed, fall back to raw URI | |
| filename = g_strdup(*uri); | |
| } | |
| if (builder->len > 0) { | |
| g_string_append(builder, "\n"); | |
| } | |
| g_string_append(builder, filename); | |
| g_free(filename); | |
| // build newline-separated list of URIs (keep them as URIs for Dart) | |
| GString *builder = g_string_new(NULL); | |
| for (gchar **uri = uris; *uri; uri++) { | |
| if (builder->len > 0) { | |
| g_string_append(builder, "\n"); | |
| } | |
| g_string_append(builder, *uri); |
Copilot
AI
Feb 26, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The fallback path uses gtk_selection_data_get_data() and then g_strdup((gchar*)data), but gtk_selection_data_get_data() returns a byte buffer that is not guaranteed to be NUL-terminated. This can lead to reading past the buffer or truncation if embedded NULs exist. Use gtk_selection_data_get_text() for text targets, or use gtk_selection_data_get_length() and g_strndup() to duplicate a bounded buffer safely.
| // fallback to the raw data as before | |
| auto *data = gtk_selection_data_get_data(sdata); | |
| if (data) { | |
| text = g_strdup((gchar *)data); | |
| // fallback to the raw data as before, but respect the buffer length | |
| gint length = gtk_selection_data_get_length(sdata); | |
| const guchar *data = gtk_selection_data_get_data(sdata); | |
| if (data != nullptr && length > 0) { | |
| text = g_strndup((const gchar *)data, (gsize)length); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
PR description mentions updates to CHANGELOG.md (an “Unreleased” entry) and the example app’s
printFilesfor defensive path handling, but those changes aren’t present in this PR branch (CHANGELOG has no “Unreleased” section; exampleprintFilesstill callslastModified/lengthwithout guards). Either include those commits or adjust the PR description so it matches what’s being merged.