mirror of
https://we.phorge.it/source/phorge.git
synced 2024-12-19 12:00:55 +01:00
Give users an explicit error if they try to upload a too-large diff to Differential
Summary: Ref T8612. If a change affects more than 10K paths + hunks, tell the user it's too big and don't bother trying to write it. We're mostly bounded by INSERTs here. Also, fix an issue with file upload errors. The keys are real PHP constants, but were accidentally converted to strings in D12797, causing every error to show as "unknown error". Test Plan: {F1057509} Reviewers: joshuaspence Reviewed By: joshuaspence Maniphest Tasks: T8612 Differential Revision: https://secure.phabricator.com/D14977
This commit is contained in:
parent
2c293bdca8
commit
efba69a440
2 changed files with 31 additions and 8 deletions
|
@ -43,6 +43,26 @@ final class DifferentialCreateRawDiffConduitAPIMethod
|
|||
$changes = $parser->parseDiff($raw_diff);
|
||||
$diff = DifferentialDiff::newFromRawChanges($viewer, $changes);
|
||||
|
||||
// We're bounded by doing INSERTs for all the hunks and changesets, so
|
||||
// estimate the number of inserts we'll require.
|
||||
$size = 0;
|
||||
foreach ($diff->getChangesets() as $changeset) {
|
||||
$hunks = $changeset->getHunks();
|
||||
$size += 1 + count($hunks);
|
||||
}
|
||||
|
||||
$raw_limit = 10000;
|
||||
if ($size > $raw_limit) {
|
||||
throw new Exception(
|
||||
pht(
|
||||
'The raw diff you have submitted is too large to parse (it affects '.
|
||||
'more than %s paths and hunks). Differential should only be used '.
|
||||
'for changes which are small enough to receive detailed human '.
|
||||
'review. See "Differential User Guide: Large Changes" in the '.
|
||||
'documentation for more information.',
|
||||
new PhutilNumber($raw_limit)));
|
||||
}
|
||||
|
||||
$diff_data_dict = array(
|
||||
'creationMethod' => 'web',
|
||||
'authorPHID' => $viewer->getPHID(),
|
||||
|
|
|
@ -4,26 +4,29 @@ final class PhabricatorFileUploadException extends Exception {
|
|||
|
||||
public function __construct($code) {
|
||||
$map = array(
|
||||
'UPLOAD_ERR_INI_SIZE' => pht(
|
||||
UPLOAD_ERR_INI_SIZE => pht(
|
||||
"Uploaded file is too large: current limit is %s. To adjust ".
|
||||
"this limit change '%s' in php.ini.",
|
||||
ini_get('upload_max_filesize'),
|
||||
'upload_max_filesize'),
|
||||
'UPLOAD_ERR_FORM_SIZE' => pht(
|
||||
UPLOAD_ERR_FORM_SIZE => pht(
|
||||
'File is too large.'),
|
||||
'UPLOAD_ERR_PARTIAL' => pht(
|
||||
UPLOAD_ERR_PARTIAL => pht(
|
||||
'File was only partially transferred, upload did not complete.'),
|
||||
'UPLOAD_ERR_NO_FILE' => pht(
|
||||
UPLOAD_ERR_NO_FILE => pht(
|
||||
'No file was uploaded.'),
|
||||
'UPLOAD_ERR_NO_TMP_DIR' => pht(
|
||||
UPLOAD_ERR_NO_TMP_DIR => pht(
|
||||
'Unable to write file: temporary directory does not exist.'),
|
||||
'UPLOAD_ERR_CANT_WRITE' => pht(
|
||||
UPLOAD_ERR_CANT_WRITE => pht(
|
||||
'Unable to write file: failed to write to temporary directory.'),
|
||||
'UPLOAD_ERR_EXTENSION' => pht(
|
||||
UPLOAD_ERR_EXTENSION => pht(
|
||||
'Unable to upload: a PHP extension stopped the upload.'),
|
||||
);
|
||||
|
||||
$message = idx($map, $code, pht('Upload failed: unknown error.'));
|
||||
$message = idx(
|
||||
$map,
|
||||
$code,
|
||||
pht('Upload failed: unknown error (%s).', $code));
|
||||
parent::__construct($message, $code);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue