From fcd9821d106bc9e80d848a6999843e6af840fd36 Mon Sep 17 00:00:00 2001 From: mrT23 Date: Wed, 20 Sep 2023 15:57:06 +0300 Subject: [PATCH 1/2] protections --- pr_agent/algo/git_patch_processing.py | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/pr_agent/algo/git_patch_processing.py b/pr_agent/algo/git_patch_processing.py index 1a2bd22bd..793663546 100644 --- a/pr_agent/algo/git_patch_processing.py +++ b/pr_agent/algo/git_patch_processing.py @@ -40,6 +40,10 @@ def extend_patch(original_file_str, patch_str, num_lines) -> str: extended_patch_lines.extend( original_lines[start1 + size1 - 1:start1 + size1 - 1 + num_lines]) + res = list(match.groups()) + for i in range(len(res)): + if res[i] is None: + res[i] = 0 try: start1, size1, start2, size2 = map(int, match.groups()[:4]) except: # '@@ -0,0 +1 @@' case @@ -207,10 +211,15 @@ def convert_to_hunks_with_lines_numbers(patch: str, file) -> str: old_content_lines = [] if match: prev_header_line = header_line + + res = list(match.groups()) + for i in range(len(res)): + if res[i] is None: + res[i] = 0 try: - start1, size1, start2, size2 = map(int, match.groups()[:4]) + start1, size1, start2, size2 = map(int, res[:4]) except: # '@@ -0,0 +1 @@' case - start1, size1, size2 = map(int, match.groups()[:3]) + start1, size1, size2 = map(int, res[:3]) start2 = 0 elif line.startswith('+'): From 992f51a0197d008fc6a58a8c92ec58bbaa9bac4a Mon Sep 17 00:00:00 2001 From: mrT23 Date: Wed, 20 Sep 2023 15:59:35 +0300 Subject: [PATCH 2/2] protections --- pr_agent/algo/git_patch_processing.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/pr_agent/algo/git_patch_processing.py b/pr_agent/algo/git_patch_processing.py index 793663546..58d05235e 100644 --- a/pr_agent/algo/git_patch_processing.py +++ b/pr_agent/algo/git_patch_processing.py @@ -45,11 +45,11 @@ def extend_patch(original_file_str, patch_str, num_lines) -> str: if res[i] is None: res[i] = 0 try: - start1, size1, start2, size2 = map(int, match.groups()[:4]) + start1, size1, start2, size2 = map(int, res[:4]) except: # '@@ -0,0 +1 @@' case - start1, size1, size2 = map(int, match.groups()[:3]) + start1, size1, size2 = map(int, res[:3]) start2 = 0 - section_header = match.groups()[4] + section_header = res[4] extended_start1 = max(1, start1 - num_lines) extended_size1 = size1 + (start1 - extended_start1) + num_lines extended_start2 = max(1, start2 - num_lines)