Limit SVG file size to 512 KiB

pull/217/head
M66B 9 months ago
parent 821759ca9b
commit b4bcc2cff4

@ -3750,7 +3750,7 @@ public class AdapterMessage extends RecyclerView.Adapter<AdapterMessage.ViewHold
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);

@ -2603,7 +2603,7 @@ public class FragmentOptionsMisc extends FragmentBase implements SharedPreferenc
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));

@ -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(
@ -280,7 +280,8 @@ class ImageHelper {
@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
@ -335,6 +336,7 @@ class ImageHelper {
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);
@ -363,6 +365,10 @@ class ImageHelper {
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);

Loading…
Cancel
Save