It's not really possible to prevent that. E.g. a well crafted image can easily trigger an RCE on some older versions of Android: https://nakedsecurity.sophos.com/2019/02/08/android-vulnerab...
Issues like this exist at all layers of the stack, so anything touching the internet needs regular security patches.