diff --git a/src/applications/differential/conduit/DifferentialCreateRawDiffConduitAPIMethod.php b/src/applications/differential/conduit/DifferentialCreateRawDiffConduitAPIMethod.php index c69a06bd9a..5d446d4fbb 100644 --- a/src/applications/differential/conduit/DifferentialCreateRawDiffConduitAPIMethod.php +++ b/src/applications/differential/conduit/DifferentialCreateRawDiffConduitAPIMethod.php @@ -1,76 +1,96 @@ 'required string', 'repositoryPHID' => 'optional string', 'viewPolicy' => 'optional string', ); } protected function defineReturnType() { return 'nonempty dict'; } protected function execute(ConduitAPIRequest $request) { $viewer = $request->getUser(); $raw_diff = $request->getValue('diff'); $repository_phid = $request->getValue('repositoryPHID'); if ($repository_phid) { $repository = id(new PhabricatorRepositoryQuery()) ->setViewer($viewer) ->withPHIDs(array($repository_phid)) ->executeOne(); if (!$repository) { throw new Exception( pht('No such repository "%s"!', $repository_phid)); } } $parser = new ArcanistDiffParser(); $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(), 'repositoryPHID' => $repository_phid, 'lintStatus' => DifferentialLintStatus::LINT_SKIP, 'unitStatus' => DifferentialUnitStatus::UNIT_SKIP, ); $xactions = array( id(new DifferentialTransaction()) ->setTransactionType(DifferentialDiffTransaction::TYPE_DIFF_CREATE) ->setNewValue($diff_data_dict), ); if ($request->getValue('viewPolicy')) { $xactions[] = id(new DifferentialTransaction()) ->setTransactionType(PhabricatorTransactions::TYPE_VIEW_POLICY) ->setNewValue($request->getValue('viewPolicy')); } id(new DifferentialDiffEditor()) ->setActor($viewer) ->setContentSourceFromConduitRequest($request) ->setContinueOnNoEffect(true) ->setLookupRepository(false) // respect user choice ->applyTransactions($diff, $xactions); return $this->buildDiffInfoDictionary($diff); } } diff --git a/src/applications/files/exception/PhabricatorFileUploadException.php b/src/applications/files/exception/PhabricatorFileUploadException.php index 095565793f..388e52411c 100644 --- a/src/applications/files/exception/PhabricatorFileUploadException.php +++ b/src/applications/files/exception/PhabricatorFileUploadException.php @@ -1,29 +1,32 @@ 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); } }