amethyst icon indicating copy to clipboard operation
amethyst copied to clipboard

[BUG] Very large image files cause app to crash

Open libertas-primordium opened this issue 1 year ago • 4 comments

Describe the bug If somebody links an image in a post that is extremely large, the app will try to render it and promptly crash.

To Reproduce Last night for shits and giggles I created a 1920*10000000 pixel image and uploaded it to nostr.build.

I then linked the image in a Nostr note on Amethyst and posted it.

As soon as Amethyst scrolls near the offending post it immediately crashes. Several other users reported the same behavior.

Expected behavior Damus and Primal users reported that their clients simply fail to render the image, showing a blank post. This is probably the better outcome.

Amethyst should filter images beyond a certain dimension limit and not attempt to automatically load them when the user scrolls near them.

Device (please complete the following information):

  • Pixel 7 pro
  • 5.10.177-android13-4-00003-ga7208022a7ea-ab10815828
  • Amethyst version 0.83.7-play

libertas-primordium avatar Jan 22 '24 19:01 libertas-primordium

No way to solve this ourselves. We will need to wait for a fix on the library we use to display images.

vitorpamplona avatar Jan 22 '24 19:01 vitorpamplona

likely related to https://github.com/coil-kt/coil/issues/1349

delki8 avatar Jan 24 '24 17:01 delki8

No way to solve this ourselves. We will need to wait for a fix on the library we use to display images.

FWIW coil can't solve this for you. You'll need to sub-sample large images using a library like https://github.com/panpf/zoomimage or (my own) https://github.com/saket/telephoto.

saket avatar Apr 27 '24 21:04 saket

Coil's image sampling logic is to simply map the size of the original Bitmap to the final Size.

Tried customizing a SizeResolver like RealViewSizeResolver but still no success since we don't know the size of the incoming Bitmap. Assume if the image is 100*100 and we give it a Size(1000, 1000), it will be sampled to 1000.

maxHeight must be combined with View size, Bitmap size and ScaleType, which is a bit complicated for us to handle.

oOJohn6Oo avatar May 17 '24 03:05 oOJohn6Oo