Closed Bug 1732681 Opened 3 years ago Closed 3 years ago

Sending an image in a Telegram chat doesn't work and causes high CPU usage

Categories

(Core :: Graphics: Canvas2D, defect)

Desktop
Linux
defect

Tracking

()

RESOLVED FIXED
Tracking Status
firefox-esr78 --- unaffected
firefox-esr91 --- unaffected
firefox92 --- unaffected
firefox93 --- fixed
firefox94 --- fixed

People

(Reporter: marco, Unassigned)

References

(Regression)

Details

(Keywords: regression)

STR:

  1. Capture a screenshot of an area of a page
  2. Paste it in a Telegram chat

The image is not pasted, and CPU usage increases and stays high until closing Firefox.

I can't reproduce in a clean profile.

Which OS is that?

Flags: needinfo?(mcastelluccio)

(In reply to Martin Stránský [:stransky] (ni? me) from comment #3)

Which OS is that?

Linux.

I can only reproduce when I copy a large enough image.

Mozregression points me to bug 1367251. Jeff, Angus, any idea?

Flags: needinfo?(mcastelluccio)
Flags: needinfo?(jgilbert)
Flags: needinfo?(angus.sawyer)
OS: Unspecified → Linux
Hardware: Unspecified → Desktop

Which telegram client? There appear to be several.

Flags: needinfo?(angus.sawyer) → needinfo?(mcastelluccio)

A quick scan through the source of the Telegram Z client shows it uses createImageBitmap and attempts to use the resize option properties. These options aren't implemented yet, and are ignored without raising an exception, why this leads to high CPU usage is unclear, since the code will just create an imageBitmap of the source image, without resizing. Are you pasting an very large image?

(In reply to Angus Sawyer from comment #6)

A quick scan through the source of the Telegram Z client shows it uses createImageBitmap and attempts to use the resize option properties. These options aren't implemented yet, and are ignored without raising an exception, why this leads to high CPU usage is unclear, since the code will just create an imageBitmap of the source image, without resizing. Are you pasting an very large image?

Yes, I'm using the https://web.telegram.org/z/ client (I think it is the default nowadays, I haven't really chosen it).

It works well if I paste a small image. It doesn't work if I paste a large image (but basically with a HiDPI screen any screenshot, even of small DOM nodes, is large).

Flags: needinfo?(mcastelluccio)

I have worked out the cause of the high CPU etc you are seeing.

Because createImageBitmap() now accepts the options object, the Telegram client function scaleImage() assumes that the resize options are supported and returns the image created as a result, which in fact is just the same size as the image passed in.

The above resizing function is called from buildAttachment() to shrink images smaller than a predetermined size. buildAttachment() assumes the image has been resized and calls itself with the returned image at line 30 so we get an infinite loop here, constantly decoding the same image without any progress.

I have a patch for supporting the resize options, but it isn't in a state for submission, and might not be acceptable and is certainly too late for FF93, which leaves three options:

  1. Revert these patches, further delaying options support.

  2. Throw an exception for unsupported options properties, I don't know how this fits with standards, unknown option properties are ignored by FF and Chrome.

  3. Add to checks to the telegram client to avoid the infinite loop and fall back to the alternative scaling mechanism in imageResize().

Angus, do you think this could be affecting other websites than Telegram and other use cases than pasting images?

I guess it is too late for 93 at this point, but what if we revert the patches only for 94 and keep them in 95 (assuming you can implement the resize option by 95)?

We should reach out to them to fix it. It's a bug in their code, not ours.

Flags: needinfo?(jgilbert)

I have submitted a 3 line PR to the telegram client in question, that should fix this case.

There is a comment in the code that mentions that FF pre 93 doesn't support options, so someone has seen option support and assumed that resizing is supported without testing.

The telegram pattern of recusing is hopefully very rare, and any breakages would just result in an image not being resized rather than an infinite loop.

OK, thanks for the additional info. So do you think we should close this bug as WONTFIX?

Do you have a bug tracking support for the resize options?

Flags: needinfo?(angus.sawyer)

There doesn't appear to be a specific bug for the resize options, I will probably create one.
I have brought the patch to add resizing up to date, it passes the web platform tests apart from the resize quality options which are ignored.

Flags: needinfo?(angus.sawyer)

Let's fix the title and component to match reality.

Component: DOM: Copy & Paste and Drag & Drop → Canvas: 2D
Summary: Copying and pasting an image into a Telegram chat doesn't work and causes high CPU usage → Sending an image in a Telegram chat doesn't work and causes high CPU usage
Depends on: 1733559

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

For more information, please visit auto_nag documentation.

Flags: needinfo?(lsalzman)

The patch I sent for the Telegram 'Z' client has been accepted and Telegram now works with FF93.

Calling this fixed per comment 17.

Status: NEW → RESOLVED
Closed: 3 years ago
Flags: needinfo?(lsalzman)
Resolution: --- → FIXED
You need to log in before you can comment on or make changes to this bug.