feat(git): add size limits for git operations
- Added MAX_CHERRY_PICK_PATCH_BYTES limit of 100MB for cherry-pick operations - Added MAX_ACTION_CONTENT_BYTES limit of 100MB for commit action content - Added MAX_COMMIT_MESSAGE_BYTES limit of 10MB for commit messages - Added MAX_CHECK_REVISIONS limit of 10,000 for revision checks - Added MAX_REBASE_COMMITS limit of 10,000 for rebase operations - Added MAX_REBASE_PATCH_BYTES limit of 100MB for rebase patches - Added MAX_RESOLUTION_CONTENT_BYTES limit of 100MB for merge conflict resolutions - Added MAX_REVERT_PATCH_BYTES limit of 100MB for revert operations - Return InvalidArgument error when size limits are exceeded with descriptive messages
This commit is contained in:
@@ -3,6 +3,8 @@ use crate::commit::create_commit::command_ok;
|
||||
use crate::error::{GitError, GitResult};
|
||||
use crate::pb::{CreateCommitResponse, GetCommitRequest, RevertCommitRequest};
|
||||
|
||||
const MAX_REVERT_PATCH_BYTES: usize = 100 * 1024 * 1024;
|
||||
|
||||
impl GitBare {
|
||||
pub fn revert_commit(&self, request: RevertCommitRequest) -> GitResult<CreateCommitResponse> {
|
||||
let target_branch = request.branch.clone();
|
||||
@@ -79,6 +81,12 @@ impl GitBare {
|
||||
.unchecked()
|
||||
.run()?;
|
||||
let patch_data = command_ok(diff)?;
|
||||
if patch_data.len() > MAX_REVERT_PATCH_BYTES {
|
||||
return Err(GitError::InvalidArgument(format!(
|
||||
"revert patch too large ({} bytes, max {MAX_REVERT_PATCH_BYTES})",
|
||||
patch_data.len()
|
||||
)));
|
||||
}
|
||||
|
||||
let apply = duct::cmd(
|
||||
"git",
|
||||
|
||||
Reference in New Issue
Block a user