The stacktrace is similar to the one reported on XWIKI-23108.
It's not exactly the same code, actually. This one seems to be after the one that was fixed in XWIKI-23108. I will have to actually reproduce the use case to be sure to fix all cases, I guess.
This message was sent by Atlassian Jira (v9.3.0#930000-sha1:287aeb6)
If image attachments aren't displayed, see this article.