Limit zip file size

pull/207/head
M66B 4 years ago
parent 5576acfa9f
commit 1ac876fa1a

@ -1177,7 +1177,9 @@ public class FragmentOptionsDisplay extends FragmentBase implements SharedPrefer
}
});
tvUnzipHint.setText(getString(R.string.title_advanced_unzip_hint, MessageHelper.MAX_UNZIP));
tvUnzipHint.setText(getString(R.string.title_advanced_unzip_hint,
Integer.toString(MessageHelper.MAX_UNZIP_COUNT),
Helper.humanReadableByteCount(MessageHelper.MAX_UNZIP_SIZE)));
swAttachmentsAlt.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
@Override

@ -50,7 +50,6 @@ import com.sun.mail.util.FolderClosedIOException;
import com.sun.mail.util.MessageRemovedIOException;
import org.apache.commons.compress.archivers.ArchiveEntry;
import org.apache.commons.compress.archivers.ArchiveException;
import org.apache.commons.compress.archivers.ArchiveInputStream;
import org.apache.commons.compress.archivers.ArchiveStreamFactory;
import org.apache.commons.compress.compressors.gzip.GzipCompressorInputStream;
@ -99,8 +98,6 @@ import java.util.TimeZone;
import java.util.UUID;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import java.util.zip.ZipEntry;
import java.util.zip.ZipInputStream;
import javax.activation.DataHandler;
import javax.activation.FileDataSource;
@ -149,7 +146,8 @@ public class MessageHelper {
static final String HEADER_CORRELATION_ID = "X-Correlation-ID";
static final int MAX_SUBJECT_AGE = 48; // hours
static final int DEFAULT_THREAD_RANGE = 7; // 2^7 = 128 days
static final int MAX_UNZIP = 10;
static final int MAX_UNZIP_COUNT = 20;
static final long MAX_UNZIP_SIZE = 1000 * 1000 * 1000L;
static final List<String> RECEIVED_WORDS = Collections.unmodifiableList(Arrays.asList(
"from", "by", "via", "with", "id", "for"
@ -3395,6 +3393,7 @@ public class MessageHelper {
Log.i("Gzipped attachment seq=" + local.sequence + " " + name + ":" + total);
if (total <= MAX_UNZIP_SIZE) {
if (name == null &&
local.name != null && local.name.endsWith(".gz"))
name = local.name.substring(0, local.name.length() - 3);
@ -3435,6 +3434,7 @@ public class MessageHelper {
}
db.attachment().setDownloaded(attachment.id, efile.length());
}
} catch (Throwable ex) {
Log.e(ex);
db.attachment().setWarning(local.id, Log.formatThrowable(ex));
@ -3447,12 +3447,15 @@ public class MessageHelper {
int count = 0;
ArchiveEntry entry;
while ((entry = ais.getNextEntry()) != null)
if (ais.canReadEntryData(entry) && !entry.isDirectory())
if (++count > MAX_UNZIP)
if (ais.canReadEntryData(entry) && !entry.isDirectory()) {
if (entry.getSize() > MAX_UNZIP_SIZE)
count = MAX_UNZIP_COUNT;
if (++count > MAX_UNZIP_COUNT)
break;
}
Log.i("Zip entries=" + count);
if (count <= MAX_UNZIP) {
if (count <= MAX_UNZIP_COUNT) {
fis.getChannel().position(0);
ais = new ArchiveStreamFactory().createArchiveInputStream(

@ -808,7 +808,7 @@
<string name="title_advanced_monospaced_pre_hint">Plain text only messages will be considered as preformatted</string>
<string name="title_advanced_placeholders_hint">This applies to reformatted messages only</string>
<string name="title_advanced_inline_hint">Inline images are images included in the message</string>
<string name="title_advanced_unzip_hint">The contents of zip files with up to %1$d files will automatically be shown</string>
<string name="title_advanced_unzip_hint">The contents of zip files with more than %1$s files or with files larger than %2$s will not be shown</string>
<string name="title_advanced_parse_classes_hint">This will more accurately display messages, but possibly with a delay</string>
<string name="title_advanced_language_detection_hint">Language detection support depends on the device manufacturer</string>

Loading…
Cancel
Save