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

Copy-pasting from Firefox downloads image again #10564

Closed
arisudesu opened this issue Mar 18, 2021 · 33 comments
Closed

Copy-pasting from Firefox downloads image again #10564

arisudesu opened this issue Mar 18, 2021 · 33 comments

Comments

@arisudesu
Copy link

arisudesu commented Mar 18, 2021

When copying images from firefox to telegram, the latter does not insert the image data as a photo, but instead downloads the same image by url. This wastes twice the amount of traffic on re-downloading the picture.
In addition, this creates a problem when copying pictures from sites protected by authorization, because telegram does not have the same cookies - instead, it downloads the 403 page as a file and tries to send it.

Steps to reproduce (example 1)

  1. Take, for example, large photo from wikipedia (~80 MB): https://upload.wikimedia.org/wikipedia/commons/e/ec/Mona_Lisa%2C_by_Leonardo_da_Vinci%2C_from_C2RMF_retouched.jpg
  2. Right-click it and select "Copy image"
  3. Paste it into telegram input field
  4. Observe how long it is pasted

Steps to reproduce (example 2)

(You'll need account on pixiv.net - it's free)

  1. Navigate to a pixiv image, e.g.: https://www.pixiv.net/en/artworks/79037838
  2. Click on the artwork to enlarge it
  3. Right-click it and select "Copy image"
  4. Paste it into telegram input field
  5. Image is not copy-pasted, instead a 146 bytes file is prompted to send, which contains "403 Forbidden" message

Expected behaviour

Image is copy-pasted without redownload.

Actual behaviour

Telegram forces it to download again.

Configuration

Operating system: Windows 10 20H2

Version of Telegram Desktop: 2.6.1

Installation source (Linux Only) - the official website / GitHub releases / flatpak / snap / distribution package: -

Used theme: -

@ilya-fedin
Copy link
Contributor

This is not downloading, tdesktop doesn't have code to download a picture from URL when pasting...

@arisudesu
Copy link
Author

arisudesu commented Mar 19, 2021

Then please explain what's going on? Why is the file containing the html error copied to telegram, while the downloaded image is displayed in the browser? This is evidence that the telegram does not use the already downloaded picture.

Another observation is that this does not happen in chrome, edge.

@RememberTheAir
Copy link

RememberTheAir commented Mar 19, 2021

Both the examples you described don't seem to suggest that the picture is downloaded again by tdesktop

Example 1: pasting the image takes some time because the file is very large. If after pasting the image you click on "cancel", you'll see that tdesktop pasted the file uri it was sending in the input box, that is stored in some firefox cache directory (in my case it's file:///C:/Users/REDACTED/AppData/Local/Temp/Mona_Lisa,_by_Leonardo_da_Vinci,_from_C2RMF_retouched.jpg. The image is not downloaded by tdesktop again

Example 2: no idea why it sends that file instead of the picture, but apparently copy-pasting that image doesn't work in every software that supports this action (eg. try to paste it in an email)

@ilya-fedin
Copy link
Contributor

What "file instead of the picture" are you both talking about? 🤔

@RememberTheAir
Copy link

RememberTheAir commented Mar 19, 2021

If you enlarge the image of the Pixiv link in the OP and copy-paste it in tdesktop, it will be sent as this file: 79037838_p0

If you open it with a text editor, it contains this:

<html>
<head><title>403 Forbidden</title></head>
<body>
<center><h1>403 Forbidden</h1></center>
<hr><center>nginx</center>
</body>
</html>

It is sent like this:

image

@ilya-fedin
Copy link
Contributor

If you enlarge the image of the Pixiv link in the OP and copy-paste it in tdesktop

Oh, I don't want to create an account :(

@arisudesu
Copy link
Author

arisudesu commented Mar 19, 2021

I've recorded what's happening step by step with request logging on local server: https://a.pomf.cat/oldqgq.mp4.

Image is downloaded twice, first time in browser, second time by telegram (?) when pasted.

@ilya-fedin
Copy link
Contributor

ilya-fedin commented Mar 19, 2021

But tdesktop doesn't have any code for downloading any stuff on pasting. Maybe Qt does this?

@reallyuniquename
Copy link

That HTTP request comes from Firefox. I assume this has something to do with Firefox (not) caching 80MB image since I can't reproduce this with smaller files. Frankly, I don't know. Good catch though.

Also I do not recommend testing this with Pixiv, they prevent direct image access even for authorized users.

@Aokromes
Copy link
Collaborator

so, no telegram bug?

@reallyuniquename
Copy link

reallyuniquename commented Mar 20, 2021

Probably not.

But it would be better to investigate this from Telegram side because some other applications manage to paste images from Firefox without this issue.

@arisudesu
Copy link
Author

That HTTP request comes from Firefox. I assume this has something to do with Firefox (not) caching 80MB image since I can't reproduce this with smaller files. Frankly, I don't know. Good catch though.

It happens with small images too, except that you don't notice the delay.

@reallyuniquename
Copy link

It happens with small images too

For me it doesn't. Try something small like 256x256px and under 25KB. There is no additional request and no file:// thingy as @RememberTheAir described, i.e. image data is being copied by value and not by reference.

@arisudesu
Copy link
Author

It happens for me: https://a.pomf.cat/rjiwza.mp4. Github avatar is 11274 bytes long.

I don't clearly understand what is happening between telegram and firefox.

@reallyuniquename
Copy link

@arisudesu You are right, it does happen with Github avatar.

Could you try serving the same image through local python HTTP server? For me it doesn't log any additional requests. Maybe it's not just about image size. Still, looks like a caching issue on Firefox side?

@ilya-fedin
Copy link
Contributor

ilya-fedin commented Mar 27, 2021

maybe the file firefox creates in temp directory is not a regular file, but some kind of special file, so that when some app tries to access it, Firefox gets it from internal cache or (depending on cache settings) asks it from the server again? This could be some new Firefox feature and can describe why such an issue appeared only now.

@ilya-fedin
Copy link
Contributor

It happens for me: https://a.pomf.cat/rjiwza.mp4.

ah, the file is created after pasting. So it could be that Firefox sets some native handle in clipboard message, so that Windows itself asks Firefox to download file on pasting.

@ilya-fedin
Copy link
Contributor

At that point it's worth for you @arisudesu and @reallyuniquename to compare your Firefox versions

@arisudesu
Copy link
Author

Mine is 87.0, was 86.0 at the moment of opening the issue.

Meanwhile I've debugged Telegram and found what causes the download: it is weird behavior of QMimeData::text() which is used here:

return confirmSendingFiles(data, std::nullopt, data->text());

It's Qt downloads file to obtain its file:// uri for text inserted on cancel. I've disabled call to QMimeData::text() here with the code:

return confirmSendingFiles(data, std::nullopt, !data->hasImage() ? data->text() : QString());

But image is still downloaded, so I had to disable one block here:

if (const auto urls = data->urls(); !urls.empty()) {
auto list = Storage::PrepareMediaList(
urls,
st::sendMediaPreviewSize);
if (list.error != Ui::PreparedList::Error::NonLocalUrl) {
if (list.error == Ui::PreparedList::Error::None
|| !hasImage) {
const auto emptyTextOnCancel = QString();
list.overrideSendImagesAsPhotos = overrideSendImagesAsPhotos;
confirmSendingFiles(std::move(list), emptyTextOnCancel);
return true;
}
}
}

with check on hasUrls():

if (hasImage && data->hasUrls()) {
    // original code
}

The image isn't downloaded anymore. No file uri is inserted on cancel too, though does it make sense? I don't know.

@ilya-fedin
Copy link
Contributor

ilya-fedin commented Mar 27, 2021

though does it make sense?

it's a bug as well (#8265) UPD: the code looks like it's done on a reason

@arisudesu
Copy link
Author

Great. Now you can fix both problems in one go.

Although I have already set up a working environment and a fix, it is unlikely I'll be able to make a patch, because Telegram code is huge and I can't be sure if I don't break something else by accident. I leave this to core developers.

@stale
Copy link

stale bot commented Sep 26, 2021

Hey there!

This issue was inactive for a long time and will be automatically closed in 30 days if there isn't any further activity. We therefore assume that the user has lost interest or resolved the problem on their own.

Don't worry though; if this is an error, let us know with a comment and we'll be happy to reopen the issue.

Thanks!

@stale stale bot added the stale label Sep 26, 2021
@aprosvetova
Copy link

Unfortunately, the issue is still present on the latest stable version.

@stale stale bot removed the stale label Sep 26, 2021
@stale
Copy link

stale bot commented Mar 27, 2022

Hey there!

This issue was inactive for a long time and will be automatically closed in 30 days if there isn't any further activity. We therefore assume that the user has lost interest or resolved the problem on their own.

Don't worry though; if this is an error, let us know with a comment and we'll be happy to reopen the issue.

Thanks!

@stale stale bot added the stale label Mar 27, 2022
@arisudesu
Copy link
Author

Unfortunately, the issue is still present on the latest stable version.

This bot is kinda useless tbh.

@stale stale bot removed the stale label Mar 27, 2022
@Aokromes
Copy link
Collaborator

no it's not, it helps us to close already fixed non-closed issues.

@ilya-fedin
Copy link
Contributor

ilya-fedin commented Mar 27, 2022

Yeah, stale bot is really useful. People open a lot of issues everyday and stalebot helps rotate them closing issues no one interested in. People like create duplicates and there's no manpower to check all the issues, the time when auto-closer bot was broken and there were no stalebot yet shown that issues reach 1000 numbers very quickly without rotation. An imperfect solution for imperfect world.

@github-actions
Copy link

Hey there!

This issue was inactive for a long time and will be automatically closed in 30 days if there isn't any further activity. We therefore assume that the user has lost interest or resolved the problem on their own.

Don't worry though; if this is an error, let us know with a comment and we'll be happy to reopen the issue.

Thanks!

@github-actions github-actions bot added the stale label Sep 24, 2022
@seiya-git
Copy link

Unfortunately, the issue is still present on the latest stable version.

@ilya-fedin
Copy link
Contributor

This issue is now a part of #25126

@github-actions github-actions bot removed the stale label Sep 25, 2022
@seiya-git
Copy link

Unfortunately, the issue is still present on the latest stable version.

@ilya-fedin
Copy link
Contributor

No one helped with reporting it to Qt sadly and it seems it has too little priority for @john-preston to look at it

@john-preston
Copy link
Member

Ok, it looks like I fixed this. We'll check in the next version.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Apr 23, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

8 participants