Skip to content

Commit

Permalink
Limit SVG file size to 512 KiB
Browse files Browse the repository at this point in the history
  • Loading branch information
M66B committed Jan 7, 2025
1 parent 821759c commit b4bcc2c
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 4 deletions.
2 changes: 1 addition & 1 deletion app/src/main/java/eu/faircode/email/AdapterMessage.java
Original file line number Diff line number Diff line change
Expand Up @@ -3750,7 +3750,7 @@ private void bindAttachments(final TupleMessageEx message, @Nullable List<Entity

boolean hide_attachments = properties.getValue("hide_attachments", message.id, hide_attachments_default);
boolean show_inline = properties.getValue("inline", message.id);
boolean svg = prefs.getBoolean("svg", !Helper.isPlayStoreInstall());
boolean svg = prefs.getBoolean("svg", true);
boolean webp = prefs.getBoolean("webp", true);

Log.i("Hide attachments=" + hide_attachments + " Show inline=" + show_inline);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2603,7 +2603,7 @@ private void setOptions() {
etNativeArcWhitelist.setText(prefs.getString("native_arc_whitelist", null));
swStrictAlignment.setEnabled(swNativeDkim.isEnabled() && swNativeDkim.isChecked());
swStrictAlignment.setChecked(prefs.getBoolean("strict_alignment", false));
swSvg.setChecked(prefs.getBoolean("svg", !Helper.isPlayStoreInstall()));
swSvg.setChecked(prefs.getBoolean("svg", true));
swWebp.setChecked(prefs.getBoolean("webp", true));
swAnimate.setChecked(prefs.getBoolean("animate_images", true));
swPreviewHidden.setChecked(prefs.getBoolean("preview_hidden", true));
Expand Down
10 changes: 8 additions & 2 deletions app/src/main/java/eu/faircode/email/ImageHelper.java
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ class ImageHelper {
private static final int MAX_PROBE = 128 * 1024; // bytes
private static final int SLOW_CONNECTION = 2 * 1024; // Kbps
private static final int MAX_BITMAP_SIZE = 100 * 1024 * 1024; // RecordingCanvas.MAX_BITMAP_SIZE
private static final int MAX_SVG_SIZE = 1024 * 1024; // bytes
private static final int MAX_SVG_SIZE = 512 * 1024; // bytes

// https://developer.android.com/guide/topics/media/media-formats#image-formats
static final List<String> IMAGE_TYPES = Collections.unmodifiableList(Arrays.asList(
Expand Down Expand Up @@ -280,7 +280,8 @@ static Bitmap makeCircular(Bitmap bitmap, Integer radius) {

@NonNull
static Bitmap renderSvg(InputStream _is, int fillColor, int scaleToPixels) throws IOException {
try (InputStream is = new Helper.MaximumLengthStream(_is, 1024 * 1024)) {
// https://dev.w3.org/SVG/tools/svgweb/samples/svg-files/
try (InputStream is = new Helper.MaximumLengthStream(_is, MAX_SVG_SIZE)) {
// https://bugzilla.mozilla.org/show_bug.cgi?id=455100
// https://bug1105796.bmoattachments.org/attachment.cgi?id=8529795
// https://github.com/BigBadaboom/androidsvg/issues/122#issuecomment-361902061
Expand Down Expand Up @@ -335,6 +336,7 @@ private static Drawable decodeImage(final Context context, final long id,
boolean show, int zoom, final float scale, final TextView view) {
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);
boolean inline = prefs.getBoolean("inline_images", false);
boolean svg = prefs.getBoolean("svg", true);
boolean webp = prefs.getBoolean("webp", true);

final int px = Helper.dp2pixels(context, (zoom + 1) * 24);
Expand Down Expand Up @@ -363,6 +365,10 @@ private static Drawable decodeImage(final Context context, final long id,
Drawable d = ContextCompat.getDrawable(context, R.drawable.twotone_broken_image_24);
d.setBounds(0, 0, px, px);
return d;
} else if ("image/svg+xml".equalsIgnoreCase(attachment.type) && !svg) {
Drawable d = ContextCompat.getDrawable(context, R.drawable.twotone_warning_24);
d.setBounds(0, 0, px, px);
return d;
} else if ("image/webp".equalsIgnoreCase(attachment.type) && !webp) {
Drawable d = ContextCompat.getDrawable(context, R.drawable.twotone_warning_24);
d.setBounds(0, 0, px, px);
Expand Down

0 comments on commit b4bcc2c

Please sign in to comment.