EionRobb / purple-discord

A libpurple/Pidgin plugin for Discord
GNU General Public License v3.0
381 stars 43 forks source link

Inline images truncated #408

Open chainria opened 2 years ago

chainria commented 2 years ago

I often exchange screenshots with friends and I really liked this new function. However, the inline images always got truncated in the message log. Today I looked into my log folder and found them truncated aswell! It seems there is a magical limit of exactly 1MB in size. I don't know if it's maybe even an upstream bug (Pidgin?) but I have no way of testing that, unfortunately.

Still, if I can be of any help, I will try my best!

EionRobb commented 2 years ago

Oh! That explains a lot. Yeah, there is a default limit of 1MB it turns out https://github.com/EionRobb/purple-discord/blob/master/purple2compat/http.c#L50 And we never set a max anywhere. There should be a bunch of error messages in the Buddy List -> Help -> Debug Window log to say "Maximum length exceeded, truncating" too.

What's a good max size to set? Don't want anything too large that it could eat up too much memory and crash, but don't want too small that images are getting cropped. 10MB?

chainria commented 2 years ago

Thank you very much for the quick response. Well, I think most of them should be around or smaller than 3 MB, so I'd say 5 should be enough, 10 almost looks like too much but maybe a good size for almost everyone. Plus, I guess only one zero needs to be added to the constant ;)

Afar from that, I think this setting should be configurable in the long run, maybe right below the "max width" parameter, the 1 MB could be a sane default then.

And last but not least, I really think truncated images should be discarded, not saved and not displayed (only the link as if the option to show them was disabled, maybe with a note the image is too big?). I ended up with 170 MB of 170 broken images in my log folder now ;) And the worst of it is, I thought they ware saved, now that I don't have access to the channel anymore, I can't even get them back :(

Edit: A question aside, I see the image names are hashed in a way, are those random, or is there an algo somewhere? I'd like to try to refetch those images I can from the CDN.

Edit 2: I wrote a simple script which parses the XML logs and refetches the broken images. Should anyone be interested, feel free to contact me!

mousethief commented 2 years ago

I'm interested in this refetch script, and asking if this bug should not link to it.

chainria commented 2 years ago

I'm interested in this refetch script, and asking if this bug should not link to it.

Here you go: https://gist.github.com/chainria/a4ec3543d3ea0493d4c7e5f1f250d043

chainria commented 2 years ago

What's a good max size to set? Don't want anything too large that it could eat up too much memory and crash, but don't want too small that images are getting cropped. 10MB?

After quite a large sample size I can say that 3MB would be a very sane default. If anyone needs more or less, the constanct can be patched of course. But I still think a setting would be the best way to go.