status-im / status-desktop

Status Desktop client made in Nim & QML
https://status.app
Mozilla Public License 2.0
290 stars 78 forks source link

[StatusChatInput] Some images do not get pasted in the chat input #10926

Closed jrainville closed 2 months ago

jrainville commented 1 year ago

Bug Report

Description

Some images do no show in the Status Input when pasted and are not submitted after pressing enter either.

Steps to reproduce

  1. Open the image in this link https://media.discordapp.net/attachments/927668982964715521/1115199506624024617/IMG_20230605_104339.jpg?width=1556&height=779 (if the link is dead, use the image below)
  2. Right click on it and select copy image
  3. Go in a community and hit CTRL+V

Result: an empty image appears. You can hover and see the X, but it doesn't show the image itself. Submitting the message just closes the input and doesn't send anything

Expected behavior

Image is shown when pasted and can get sent as a message

Actual behavior

No image is shown, except the empty image zone

Additional Information

Warning: qrc:/imports/shared/status/StatusChatInputImageArea.qml:24:13: QML Image: Error decoding: data:image/jpeg;base64,: Unsupported image format (qrc:/imports/shared/status/StatusChatInputImageArea.qml:24, )

image

jrainville commented 1 year ago

The issue is only with pasting.

Drag and drop works.

I printed the format (img.format()) and it returns 0, which is QImage::Format_Invalid.

However, the same image can be drag and dropped in the app, or pasted in Discord, so something is weird here.

I'll continue investigating

jrainville commented 1 year ago

I also found that if I download the image, open it in my Image Viewer, then copying it and pasting it works fine.

If I open it in the browser and do the same, it doesn't work.

jrainville commented 1 year ago

Some more updates:

The pasting works, but very rarely and randomly. I would say 5% of the time it will work.

I also tried adding a retry to the clipboard read in case there was a race condition in accessing the clipboard, but no luck.

caybro commented 1 year ago

What can I say.... I can't reproduce at all:

image

Worked 10/10

Just FYI:

jrainville commented 1 year ago

@caybro how were you trying? For me, the way to reproduce consistently was opening this link in Brave (maybe the browser makes a difference) and clicking Copy Image from the right-click menu.

Downloading the image and opening in Brave also does the same. If I opened in the image viewer, then like you, it would work 100%

caybro commented 1 year ago

@caybro how were you trying? For me, the way to reproduce consistently was opening this link in Brave (maybe the browser makes a difference) and clicking Copy Image from the right-click menu.

Opened here in Google Chrome; I can try other browser, just a sec :)

caybro commented 1 year ago

OK, so copy&paste from Firefox worked fine as well but when I tried DND:

Fatal: Object 0x111cd300 destroyed while one of its QML signal handlers is in progress.
Most likely the object was deleted synchronously (use QObject::deleteLater() instead), or the application is running a nested event loop.
This behavior is NOT supported!
qrc:/imports/shared/status/StatusChatInput.qml:953: function() { [native code] } (:0, )
Traceback (most recent call last)
/home/ltinkl/git/status/status-desktop/src/nim_status_client.nim(193) nim_status_client
/home/ltinkl/git/status/status-desktop/src/nim_status_client.nim(166) mainProc
/home/ltinkl/git/status/status-desktop/src/app/boot/app_controller.nim(287) delete
/home/ltinkl/git/status/status-desktop/src/app/global/global_singleton.nim(75) delete
/home/ltinkl/git/status/status-desktop/vendor/nimqml/src/nimqml/private/qqmlapplicationengine.nim(40) delete
SIGABRT: Abnormal termination.
make: *** [Makefile:753: run-linux] Neúspěšně ukončen (SIGABRT) (obraz paměti uložen)
19:31:13: make exited with code 2

Ok, we have a problem here :)

caybro commented 1 year ago

image

jrainville commented 1 year ago

but when I tried DND:

For me DnD always worked :thinking:

The stack trace is not helpful either.

Is the crash reproducible?

caybro commented 1 year ago

Yeah the DND crash from Firefox is 100% reproducible on my side but doesn't happen at all when dragging from Chrome... gremlins

caybro commented 1 year ago

I'll debug the DND/Firefox crash tomorrow, looks like the URL format there is somehow different/non-standard

caybro commented 1 year ago

OK some progress: the Firefox crash happens inside the StatusChatImageSizeValidator; if disabled it still doesn't work because the URL check fails StatusChatImageExtensionValidator due to the URL containing a query, like:

Warning: !!! isValidImageUrl QUrl("https://media.discordapp.net/attachments/927668982964715521/1115199506624024617/IMG_20230605_104339.jpg?width=1556&height=779")

It fails simply because the URL doesn't end with Constants.acceptedDragNDropImageExtensions.

Fixing :)

caybro commented 1 year ago

The crash happens in Utils.qml, function isFilesizeValid(img) in:

let size = parseInt(globalUtils.getFileSize(img))

so I suspect inside some NIM code

caybro commented 1 year ago

...which doesn't make sense as it's either a binary blob, and then we have already a check in place, or it's a URL that can't be opened (it's not a local file)

EDIT: got it, it can be a local file in case we get here from the file dialog (it's still a URL though)

caybro commented 1 year ago

@jrainville ok so I was finally able to reproduce, albeit with DND only (copy/paste from clipboard of this image still works):

The error in console:

Warning: QImage::scaled: Image is a null image (:0, )
DBG 2023-06-06 22:31:30.704+02:00 NewBE_callPrivateRPC                       topics="rpc" tid=207156 file=core.nim:27 rpc_method=wakuext_sendChatMessages
ERR 2023-06-06 22:31:30.706+02:00 rpc response error                         topics="rpc" tid=207156 file=core.nim:36 err="\nstatus-go error [methodName:wakuext_sendChatMessages, code:-32000, message:EOF ]\n"
ERR 2023-06-06 22:31:30.706+02:00 error doing rpc request                    topics="rpc" tid=207156 file=core.nim:40 methodName=wakuext_sendChatMessages exception="\nstatus-go error [methodName:wakuext_sendChatMessages, code:-32000, message:EOF ]\n"
ERR 2023-06-06 22:31:30.706+02:00 Error sending images                       topics="chat-service" tid=207156 file=service.nim:503 msg="\nstatus-go error [methodName:wakuext_sendChatMessages, code:-32000, message:EOF ]\n"

Does this ring a bell?

image

caybro commented 1 year ago

Esp. the part with Warning: QImage::scaled: Image is a null image (:0, ) leads me to think we screw the image when scaling it

jrainville commented 1 year ago

Does this ring a bell?

The Image is a null image error is similar to what I had, but my repro step doesn't even reach the scaling.

The image in the clipboard itself is considered Null, even though it does understand that it is an image.

Anyway, this particular issue seems really annoying to fix. I moved it to 0.14, so we can retry later.

The issue you have seems to be different, so it might be worth to add to the backlog too. Probably to 0.14 for now as well.

caybro commented 1 year ago

Does this ring a bell?

The Image is a null image error is similar to what I had, but my repro step doesn't even reach the scaling.

I fixed some things locally (which I'll post in a PR anyway, fixes the crashes I had) so I got further

The image in the clipboard itself is considered Null, even though it does understand that it is an image.

The image in the clipboard is fine, I checked. Warning: QImage::scaled it gets somehow destroyed when we scale it

jrainville commented 1 year ago

The image in the clipboard is fine, I checked. Warning: QImage::scaled it gets somehow destroyed when we scale it

Yeah, it seems like we don't have the same issue.

Here is what happens for me:

pasting.webm

You can see that it fails in the imageBase64 function, which is before any scaling happens.

If I take the same image and open it in the image viewer instead, the same flow works and the format is 4 instead of 0.

caybro commented 1 year ago

@jrainville what's the browser you copy from? Can you try to do the same with either Chrome or Firefox?

caybro commented 1 year ago

So your bug seems more in the app of origin (the one that copies the data to the clipboard).

jrainville commented 1 year ago

I use Brave. I'll try tomorrow with Firefox

On Tue, Jun 6, 2023, 5:49 p.m. Lukáš Tinkl @.***> wrote:

@jrainville https://github.com/jrainville what's the browser you copy from? Can you try to do the same with either Chrome or Firefox?

— Reply to this email directly, view it on GitHub https://github.com/status-im/status-desktop/issues/10926#issuecomment-1579494731, or unsubscribe https://github.com/notifications/unsubscribe-auth/AC27XA2VH4UPCV2OL6W72ZDXJ6QWVANCNFSM6AAAAAAY27K7DM . You are receiving this because you were mentioned.Message ID: @.***>

jrainville commented 1 year ago

Copying from Firefox works correctly, contrarily to Brave.

I'm gonna try your PR

caybro commented 1 year ago

@jrainville I'd call this specific problem a Qt bug? Copying and DND of this image works for me in every possible web browser I tried (Chrome, Firefox, Brave, Epiphany) with the https://github.com/status-im/status-desktop/pull/10975 PR

jrainville commented 1 year ago

Reopened because the issue is not fully fixed with it. It looks like this is fixed with version 5.15.8 of Qt, but our linux host still has 5.15.2.

So fixing https://github.com/status-im/status-desktop/issues/9350 would probably fix it

iurimatias commented 8 months ago

moved to 2.29 due to lack of space in this milestone

igor-sirotin commented 7 months ago

I have a screenshot png file.

image

When I drag&drop the file to Status it's sent just fine.

image

But when open Finder, select the file and click Cmd+V and paste it to Status, I get this (which is an Apple icon for images)

image
iurimatias commented 2 months ago

closing as this will be part of a wider rethink of this feature