The avatar picker reads and decodes the whole selected image into memory with no size limit before uploading. In ProfileMenu's photo-picker callback:
ByteArrayOutputStream out = new ByteArrayOutputStream();
byte[] buffer = new byte[8192];
int len;
while ((len = stream.read(buffer)) != -1) out.write(buffer, 0, len);
byte[] imageBytes = out.toByteArray();
...
Bitmap preview = BitmapFactory.decodeByteArray(imageBytes, 0, imageBytes.length);
...
String base64 = Base64.getEncoder().encodeToString(imageBytes);
The server caps avatars at 5MB and 8000x8000 and checks the header before decoding (nice), but the client does none of that first. If the user picks a big photo (modern phone cameras easily produce 20-50MP images), the client loads the whole file into a byte[], decodes it to a full-resolution Bitmap for the preview, and base64-encodes the whole thing. On a low-end device that's an easy OutOfMemoryError and a crash, and even when it doesn't crash it uploads a huge payload the server is just going to reject anyway.
Worth checking the file size up front and using BitmapFactory.Options with inSampleSize to downscale before decoding, so the client never holds the full-res bitmap.
File: android/src/com/focus/kingdom/ui/screen/ProfileMenu.java, the pickMedia callback, around line 130-154.
The avatar picker reads and decodes the whole selected image into memory with no size limit before uploading. In ProfileMenu's photo-picker callback:
The server caps avatars at 5MB and 8000x8000 and checks the header before decoding (nice), but the client does none of that first. If the user picks a big photo (modern phone cameras easily produce 20-50MP images), the client loads the whole file into a byte[], decodes it to a full-resolution Bitmap for the preview, and base64-encodes the whole thing. On a low-end device that's an easy OutOfMemoryError and a crash, and even when it doesn't crash it uploads a huge payload the server is just going to reject anyway.
Worth checking the file size up front and using BitmapFactory.Options with inSampleSize to downscale before decoding, so the client never holds the full-res bitmap.
File:
android/src/com/focus/kingdom/ui/screen/ProfileMenu.java, the pickMedia callback, around line 130-154.