Closed Bug 1742644 Opened 3 years ago Closed 2 years ago

Copy image copies two images

Categories

(Core :: Widget: Win32, defect, P2)

All
Windows
defect

Tracking

()

RESOLVED WORKSFORME

People

(Reporter: hadjii.ember.mctillhawk, Unassigned)

References

()

Details

User Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:94.0) Gecko/20100101 Firefox/94.0

Steps to reproduce:

Find an affected image url.
Right-click and choose "copy image".
Paste the image into an affected computer program.

Actual results:

Two images are pasted simultaneously.

Expected results:

One image is pasted.

There weren't any fields to provide certain critical information, so here it is.

Meaning of affected image url:
This does not occur for every image. It is not a random chance upon choosing "copy image". If a given image does not produce the bug, it will never produce the bug. If a given image does produce the bug, it will always produce the bug every time. This persists through system reboots.
The issue is not associated with any particular website. I've encountered it with both Tumblr and Google Images.

Example affected image url:
https://64.media.tumblr.com/70183e0784050923a91c9667d4271d51/4aca9f3c3ab59b8a-f5/s540x810/9a82ec029e05da461d72e8b52131759d770a75fb.png
If I copy the above image, I will always get a double copy, every time, no matter how many times I restart my computer.

Meaning of affected computer program:
Most computer programs behave alright with this, but not all. I have identified so far two that are affected. Discord, and Shapeshifter.
Discord is a popular social application.
Shapeshifter is a modifier for Windows which extends the functionality of the clipboard.

The effect in Discord is as stated above, two images are pasted instead of one.

The effect in Shapeshifter is somewhat different. Shapeshifter normally gives an image preview when copying an image; it does not here. Shapeshifter usually only gives the option to "copy as compressed folder" when copying multiple files, but it gives that option here. Choosing that option crashes the program, probably because there aren't actually two images.
The most exotic effect in Shapeshifter is through combining the three, Firefox, Discord, and Shapeshifter.

When pasting an affected image into Discord with Shapeshifter running in the background, the issue is as previously stated.
When pasting an affected image a second time without re-copying the image, something different happens.
Two images are pasted. The first one is the given image, the second image is an empty image with 0kb of data.

This does not occur when copying images from any source other than Firefox. Programs such as Opera and Paint.NET produce well-behaved images in the clipboard.

The Bugbug bot thinks this bug should belong to the 'Core::ImageLib' component, and is moving the bug to that component. Please revert this change in case you think the bot is wrong.

Component: Untriaged → ImageLib
Product: Firefox → Core

I think this is more likely to be a clipboard issue than an imagelib one

Component: ImageLib → DOM: Copy & Paste and Drag & Drop

Mirko, can you take a look on Windows?

Flags: needinfo?(mbrodesser)

Ah, why did these not show themselves earlier in my search?
It would explain the appearance in Discord.

However, it doesn't seem to explain Shapeshifter which does not look like an electron app, based on the git repository.

Ah, why did these not show themselves earlier in my search?

Presumably, because their status is set to "RESOLVED - INVALID", which is the most appropriate existing status in Bugzilla.

Shapeshifter is a modifier for Windows which extends the functionality of the clipboard.

Presumably, https://shapeshifter.app/ is meant.

See Also: → 1736944, 1716016

Filed https://github.com/ffMathy/Shapeshifter/issues/606, because this is presumably a bug in Shapeshifter.

Flags: needinfo?(mbrodesser)

Perhaps, we should move this bug to "External Software Affecting Firefox" at least for now. If Shapeshifter developers believe this is a bug of Gecko, we should take this back to "Core".

Component: DOM: Copy & Paste and Drag & Drop → Other
OS: Unspecified → Windows
Product: Core → External Software Affecting Firefox
Hardware: Unspecified → All
Version: Firefox 94 → unspecified

Masayuki: thanks, wasn't aware of that component. Makes sense.

The severity field is not set for this bug.
:gcp, could you have a look please?

For more information, please visit auto_nag documentation.

Flags: needinfo?(gpascutto)

The effect in Discord is as stated above, two images are pasted instead of one.

There is a known issue that if you right-click > Copy Image on an image in Firefox, then Ctrl+V into the Discord desktop app, the image may paste twice. It seems to be a compatibility issue with the older version of the Electron framework used in the Discord app -- it isn't completely compatible with the way Firefox puts images on the clipboard.

Ref. bug 1736944 "Firefox pasting images twice"

Maybe there's a case here that we should look into how we're putting data into the windows clipboard?

Flags: needinfo?(gpascutto) → needinfo?(spohl.mozilla.bugs)

Although this appears to have been fixed in more recent versions of Electron, let's investigate this once and for all to ensure that there is nothing to fix in Firefox.

Severity: -- → S4
Status: UNCONFIRMED → NEW
Component: Other → Widget: Win32
Ever confirmed: true
Flags: needinfo?(spohl.mozilla.bugs)
Priority: -- → P2
Product: External Software Affecting Firefox → Core

ClipView has given some rather intriguing information now. I think the bug might actually be the reverse of what I was expecting; Discord should technically always paste two images whenever copying from Firefox, even though that would be undesirable behavior.

ClipView says that when copying an image from not-Firefox, there's image data in a CF_DIB and CF_BITMAP.
When copying from Firefox, there's image data in a CF_DIB and a CF_BITMAP, but also there's a CF_HDROP entry.
Copying an image in Explorer produces a CF_HDROP but no dib or bitmap.
I suspect that when Discord is pasting the two images, it's pasting both the clipboard image data and the reference to the file.
This is strengthened by the fact that I can find the temp file for the CF_HDROP when it pastes two images, but if it only pastes one, the filename appears briefly in the temp folder, but attempting to interact with it at all makes it disappear.

Also I think I have finally figured out what determines if it's a double paste or not.

If the image is a PNG, it will double paste.
If the image is a JPG or WEBP, it will not double paste.

Sorry, I described the behavior of the temp file incorrectly. The temp file appears to be generated at the time the image is pasted, regardless of program.
I am uncertain why Firefox uses a CF_HDROP to an ephemeral file, but other browsers don't, does anyone have some information on that?

I know why PNG's double-paste in Discord now though.
If a CF_HDROP is provided, and it's for a png, then Discord will queue an image to be added. This happens regardless of whether the png even exists, if it doesn't then it'll add an empty image.
If the CF_HDROP is for an image that isn't a png, then Discord will not queue an image to be added, even if it does exist.

So that's why. When copying an image from Firefox, we have clipboard image data and an ephemeral file. When pasting, the file is brought into existence, and Discord tries to add both the clipboard image data and the file. If the file is a PNG then it'll add it, if the file isn't a PNG then it'll fail.

This may also explain why Shapeshifter didn't like it either; it probably expects the CF_HDROP to be pointing to a real file, so it keels over dead when it finds out the fun way that the file only exists briefly during the paste operation. Hard crashing cuz a random file doesn't exist is bad behavior on Shapeshifter's part, though...

One more before I go to bed, this would also explain why Shapeshifter does what it did to Discord. After the first paste, whatever it is that produces the temp file no longer is present, now Shapeshifter is handling it? Except it doesn't, it doesn't rejuvenate the temp file, but it does leave the CF_HDROP in the clipboard, so when pasting, it pastes the image data, and Discord adds an empty image because that's what Discord does when there's a CF_HDROP in the clipboard which points to a non-existent png file.

So does anyone know why Firefox uses an additional clipboard data entry when copying images that no other web browser that I know of uses?

And if we need that as the default behavior for compatibility with something, could we get a flag on about:config so users can opt-in to a different behavior?

(In reply to hadjii.ember.mctillhawk from comment #17)

Also I think I have finally figured out what determines if it's a double paste or not.

If the image is a PNG, it will double paste.
If the image is a JPG or WEBP, it will not double paste.

Showing up late, but I don't think this is it. I noticed it immediately on switching to Firefox when I was copying images off of Twitter, and looking at the files they're all JPG minus like one, yet every single type does it upon pasting into Discord.

(In reply to dracosafarius from comment #21)

(In reply to hadjii.ember.mctillhawk from comment #17)

Also I think I have finally figured out what determines if it's a double paste or not.

If the image is a PNG, it will double paste.
If the image is a JPG or WEBP, it will not double paste.

Showing up late, but I don't think this is it. I noticed it immediately on switching to Firefox when I was copying images off of Twitter, and looking at the files they're all JPG minus like one, yet every single type does it upon pasting into Discord.

Half-right. That is the current behavior, yes, because the behavior of the bug on the Discord side of things has changed now.
This bug report and the behavior described is from a year ago until recently, maybe about a month ago.
Now all images double-paste into Discord-Stable.
However, all images single-paste into Discord-Canary.

The bug is now effectively dead, at least between Firefox and Discord. No idea about Shapeshifter and also I don't actually care and that project looks dead anyways.

There is a new odd behavior, though. Any image on Pixiv does the paste behavior of "one real image and one empty" in Discord-Stable and "one empty image" in Discord-Canary.
No other web browser or website that I've tried does this.
This can be worked around by either pasting into paint.net first and then recopying into discord, or just using Brave for Pixiv and Firefox as my main driver.

Duplicate of this bug: 1800893
See Also: → 1808146

I think the original issue and pixiv issue described in comment 22 should be fixed now. Can anyone still reproduce this in Nightly?

Looks like both my original issue and the later pixiv issue are fixed in Nightly.

Status: NEW → RESOLVED
Closed: 2 years ago
Resolution: --- → WORKSFORME
You need to log in before you can comment on or make changes to this bug.