Page MenuHomePhabricator

D16714.diff
No OneTemporary

D16714.diff

diff --git a/src/applications/differential/config/PhabricatorDifferentialConfigOptions.php b/src/applications/differential/config/PhabricatorDifferentialConfigOptions.php
--- a/src/applications/differential/config/PhabricatorDifferentialConfigOptions.php
+++ b/src/applications/differential/config/PhabricatorDifferentialConfigOptions.php
@@ -70,6 +70,19 @@
);
}
+ $inline_description = $this->deformat(
+ pht(<<<EOHELP
+To include patches inline in email bodies, set this option to a positive
+integer. Patches will be inlined if they are at most that many lines and at
+most 256 times that many bytes.
+
+For example, a value of 100 means "inline patches if they are at not more than
+100 lines long and not more than 25,600 bytes large".
+
+By default, patches are not inlined.
+EOHELP
+ ));
+
return array(
$this->newOption(
'differential.fields',
@@ -254,13 +267,7 @@
'int',
0)
->setSummary(pht('Inline patches in email, as body text.'))
- ->setDescription(
- pht(
- "To include patches inline in email bodies, set this to a ".
- "positive integer. Patches will be inlined if they are at most ".
- "that many lines. For instance, a value of 100 means 'inline ".
- "patches if they are no longer than 100 lines'. By default, ".
- "patches are not inlined.")),
+ ->setDescription($inline_description),
$this->newOption(
'metamta.differential.patch-format',
'enum',
diff --git a/src/applications/differential/editor/DifferentialTransactionEditor.php b/src/applications/differential/editor/DifferentialTransactionEditor.php
--- a/src/applications/differential/editor/DifferentialTransactionEditor.php
+++ b/src/applications/differential/editor/DifferentialTransactionEditor.php
@@ -1264,11 +1264,30 @@
$config_attach = PhabricatorEnv::getEnvConfig($config_key_attach);
if ($config_inline || $config_attach) {
- $patch = $this->buildPatchForMail($diff);
- $lines = substr_count($patch, "\n");
+ $body_limit = PhabricatorEnv::getEnvConfig('metamta.email-body-limit');
- if ($config_inline && ($lines <= $config_inline)) {
- $this->appendChangeDetailsForMail($object, $diff, $patch, $body);
+ $patch = $this->buildPatchForMail($diff);
+ if ($config_inline) {
+ $lines = substr_count($patch, "\n");
+ $bytes = strlen($patch);
+
+ // Limit the patch size to the smaller of 256 bytes per line or
+ // the mail body limit. This prevents degenerate behavior for patches
+ // with one line that is 10MB long. See T11748.
+ $byte_limits = array();
+ $byte_limits[] = (256 * $config_inline);
+ $byte_limits[] = $body_limit;
+ $byte_limit = min($byte_limits);
+
+ $lines_ok = ($lines <= $config_inline);
+ $bytes_ok = ($bytes <= $byte_limit);
+
+ if ($lines_ok && $bytes_ok) {
+ $this->appendChangeDetailsForMail($object, $diff, $patch, $body);
+ } else {
+ // TODO: Provide a helpful message about the patch being too
+ // large or lengthy here.
+ }
}
if ($config_attach) {

File Metadata

Mime Type
text/plain
Expires
Fri, Apr 4, 8:41 PM (1 d, 1 h ago)
Storage Engine
blob
Storage Format
Encrypted (AES-256-CBC)
Storage Handle
7227441
Default Alt Text
D16714.diff (3 KB)

Event Timeline