Code Monkey home page Code Monkey logo

Comments (16)

andyholmes avatar andyholmes commented on June 24, 2024 1

I really have no idea why would even a clipboard library would try to load file contents.

So that it can do things like this:

Screenshot of Clipboard Indicator displaying a thumbnail of an image in the clipboard

There's no way to display a image without the contents of the image.

from gnome-shell-extension-clipboard-indicator.

andyholmes avatar andyholmes commented on June 24, 2024 1

I can't answer why the extension loads the contents of text files, rather than just displaying the filename.

Either way the bug would still exist, since I doubt there's a way for the clipboard implementation or anyone else to determine whether the mime-type is actually accurate. The source application just says "here's a blob of data, and here's the mime-type you should advertise it as".

In this case, it's just fortunate we can rely on Gio checking the content type (somewhat slowly) and not have to trust the mime-type.

from gnome-shell-extension-clipboard-indicator.

Edu4rdSHL avatar Edu4rdSHL commented on June 24, 2024 1

Thank you so much for the detailed explanation @Tudmotu, and thanks @andyholmes for the fix!

Will be there a release including this fix on the extensions website soon?

from gnome-shell-extension-clipboard-indicator.

Tudmotu avatar Tudmotu commented on June 24, 2024 1

Yeah technically the interface supports multiple mimetypes, both Wayland and X11 have multi-mimetype implementations but SelectionSourceMemory in Mutter doesn't. And since the Wayland/X11 implementations are not exposed via Gjs, this extension cannot utilize them, and we must add support in the Mutter implementation, which is exposed.

from gnome-shell-extension-clipboard-indicator.

Edu4rdSHL avatar Edu4rdSHL commented on June 24, 2024

As I said, I'm not an js expert or even competent and it may be nonsense, but can that be caused by this line?

from gnome-shell-extension-clipboard-indicator.

Tudmotu avatar Tudmotu commented on June 24, 2024

Thank you @Edu4rdSHL for reporting this.

@andyholmes would you mind explaining why does this happen (I assume you understand because you fixed it)? I cannot understand how would the extension execute a command 😳

from gnome-shell-extension-clipboard-indicator.

andyholmes avatar andyholmes commented on June 24, 2024

To be honest, I didn't trace it all the way down. The only thing that makes sense is that GdkPixbuf takes the bytes it's given and somehow ends up executing it.

I guess maybe some image formats, like maybe animated GIFs, are executables in some sense so it's capable of doing that? It sure sounds like something ridiculous an image processing library would do :/

from gnome-shell-extension-clipboard-indicator.

Edu4rdSHL avatar Edu4rdSHL commented on June 24, 2024

The thing is that it's opening binary files too, such as /usr/bin/ls, and it's happening when a specific mimetype is found. I really have no idea why would even a clipboard library would try to load file contents.

from gnome-shell-extension-clipboard-indicator.

Edu4rdSHL avatar Edu4rdSHL commented on June 24, 2024

I would even be that optimistic that if the affected mimetype is removed from the list, the issue wouldn't happen anymore, but that just a naive assumption.

from gnome-shell-extension-clipboard-indicator.

Edu4rdSHL avatar Edu4rdSHL commented on June 24, 2024

Yeah, I understand it for images, but why for a UTF-8 string.

from gnome-shell-extension-clipboard-indicator.

Tudmotu avatar Tudmotu commented on June 24, 2024

Oh damn, ok.
It would be weird for Pixbuf to execute the binary data but that sounds like a possible explanation and I have no alternative explanation.

@Edu4rdSHL I think it's like this:

  • The extension saves the mime type for every entry. That mime type is usually "text/plain" or "image/png", etc
  • Sometimes the mime type is "UTF8_STRING". Not sure why. Anyway I had to add support for it because some applications advertise their content as "UTF8_STRING" even though it's not an actual mime type
  • The extension also displays image previews in the clipboard. It identifies entries that have an image mime type and creates a small thumbnail using St.Icon
  • In order to not bloat the JSON file, the extension saves the image to a file, and saves the path of the file in the JSON
  • To create the thumbnail, the extension loads the contents of the file, using the path from the JSON

The [incomplete] theory goes like this: sometimes, the extensions tries to create an St.Icon from a file that is not an image.
For this to happen, two things need to coincide:

  1. You copy a string of a path
  2. The extension identifies the entry as an image

If these two things happen, the extension will load the binary data of the path you copied and try to create an St.Icon from it.

What I'm still missing here is: Why does the extension identify the UTF8_STRING as an image that should be loaded into a thumbnail? I can't see where the bug is.

But I understand how @andyholmes' solution solves this.

from gnome-shell-extension-clipboard-indicator.

Tudmotu avatar Tudmotu commented on June 24, 2024

@Edu4rdSHL Yes, I uploaded it to e.g.o now:
https://extensions.gnome.org/review/53581

It might take a bit before it's approved.

from gnome-shell-extension-clipboard-indicator.

Edu4rdSHL avatar Edu4rdSHL commented on June 24, 2024

Thanks! I will try to get it approved asap with the extensions team.

from gnome-shell-extension-clipboard-indicator.

andyholmes avatar andyholmes commented on June 24, 2024

Sometimes the mime type is "UTF8_STRING". Not sure why. Anyway I had to add support for it because some applications advertise their content as "UTF8_STRING" even though it's not an actual mime type

Ah, I found this in St.Clipboard some time ago:

const char *supported_mimetypes[] = {
  "text/plain;charset=utf-8",
  "UTF8_STRING",
  "text/plain",
  "STRING",
};

I would not count on that being a complete list though, because honestly why are there four to begin with, and charset= sure looks like it could hold other values :/

from gnome-shell-extension-clipboard-indicator.

Tudmotu avatar Tudmotu commented on June 24, 2024

Yeah, currently the extension tries to mimic St.Clipboard by choosing the mimetype based on a hard-coded list and querying the clipboard for these mimetypes until it finds one that has a value.

I hope this will be solved once I get to implementing the multi-mimetype support in Mutter. Unfortunately I'm not sure when I'll get to that.

Once Mutter has multi-mimetype support, this extension will no longer be opinionated on which mimetype it should keep in the history file ― it would just keep all of them. Right now it kind of "guesses" which mimetype is the most appropriate (based on the first mimetype that returns a value from the clipboard).

from gnome-shell-extension-clipboard-indicator.

andyholmes avatar andyholmes commented on June 24, 2024

Ah gotcha, that would be good. I didn't realize Mutter was missing that, since I believe the portal-side advertises API support.

from gnome-shell-extension-clipboard-indicator.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.