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

--get-sidecars prints get-sidecarsliterally (and nothing else) #1644

Open
przepompownia opened this issue Feb 20, 2025 · 4 comments
Open

--get-sidecars prints get-sidecarsliterally (and nothing else) #1644

przepompownia opened this issue Feb 20, 2025 · 4 comments
Labels

Comments

@przepompownia
Copy link

Setup (please complete the following information):

  • Distribution: [Debian]
  • Distribution release: [sid]
  • Geeqie version [Geeqie 2.5+git20250218-9f73b6cb GTK3]:

Describe the bug
As in the title. It does not depend on if grouping is enabled. I have set sidecar.ext = ".jpg;%raw;.mp4;.ufraw;.xmp;%unknown", tried also on empty value with the same output.

 $ geeqie --get-sidecars 2024-11-02_06.15.01.dng
get-sidecars

To reproduce
Like in the description, assuming that Geeqie is already running.

Expected behavior
Make it working as previously.

I haven't made bisection. Can you reproduce this bug?

@xsdg
Copy link
Contributor

xsdg commented Feb 20, 2025

This repros for me. In particular, I see this behavior regardless of the filename I attempt to pass in (even if it's one that doesn't exist).

Relevant code is here:

void gq_get_sidecars(GtkApplication *, GApplicationCommandLine *app_command_line, GVariantDict *command_line_options_dict, GList *)

Running in a debugger, it's clear that "get-sidecars" is assigned to the text variable on line 812. The documentation for the g_variant_dict_lookup function is here:
https://docs.gtk.org/glib/method.VariantDict.lookup.html

@xsdg
Copy link
Contributor

xsdg commented Feb 20, 2025

One thing I'm noticing is that text is immediately used (aka dereferenced), and if g_variant_dict_lookup fails, then text will be uninitialized, which is UB. In particular, the code doesn't check the return value for g_variant_dict_lookup before attempting to access text.

That said, it's not clear yet whether that's what's happening here.

@xsdg
Copy link
Contributor

xsdg commented Feb 20, 2025

Okay, it looks like the gq_get_sidecars function mistakenly uses file as the option key instead of get-sidecars:

Thread 1 "geeqie" hit Breakpoint 1, (anonymous namespace)::gq_get_sidecars (
    app_command_line=0x5640629665e0, command_line_options_dict=0x564063425fa0)
    at ../src/command-line-handling.cc:811
811		g_variant_dict_lookup(command_line_options_dict, "file", "&s", &text);
(gdb) p (int)g_variant_dict_contains(command_line_options_dict, "file")
$13 = 0
(gdb) p (int)g_variant_dict_contains(command_line_options_dict, "get-sidecars")
$14 = 1

gq_selection_add works correctly, and shows how this should be structured:

g_variant_dict_lookup(command_line_options_dict, "selection-add", "&s", &text);

And because g_variant_dict_contains returns false, we would expect this to be triggering UB, which could easily explain the value we're seeing.

I'm guessing this was originally a copy-paste error, but also, it would be good to check the return value for that function and to return before attempting to access text if it fails for any reason.

I'll try to put together a fix for this in the next day or two if Colin doesn't get to it (he undoubtedly understands how this is supposed to work better than I do)

@przepompownia
Copy link
Author

@xsdg thank you for detailed investigation at the moment. I hope it will be useful for fixing and tried at least partially understand what happens (not being familiar, in practice, with C/C++ and GTK library).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants