Skip to content

Commit

Permalink
Search for file in source dir if it is build generated file. (#427)
Browse files Browse the repository at this point in the history
  • Loading branch information
inferno-chromium committed Jul 4, 2024
1 parent 667f4c0 commit ddf5e51
Showing 1 changed file with 23 additions and 1 deletion.
24 changes: 23 additions & 1 deletion experimental/manual/oss_fuzz_vuln_prompt.py
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,23 @@ def get_changeset_diff(repo_url, regression_range):
raise RuntimeError(f"Error retrieving changeset diff: {e}")


def find_file(file_path, search_path):
"""Finds a file in a search path."""
# If file already exists in the search path, return as-is.
if os.path.isfile(os.path.join(search_path, file_path)):
return file_path

# Find the file in the search path folder.
filename = os.path.basename(file_path)
for root, _, files in os.walk(search_path):
if filename in files:
full_file_path = os.path.join(root, filename)
return full_file_path[len(search_path) + 1:]

# File not found.
return None


def get_file_content(repo_url, crash_revision, file_path):
"""Fetches the content of a file in a Git repository."""
local_repo_path = get_local_repo_path(repo_url)
Expand All @@ -128,10 +145,15 @@ def get_file_content(repo_url, crash_revision, file_path):
print(f"Error: Commit hash '{crash_revision}' not found in repository.")
return None

local_file_path = find_file(local_file_path, local_repo_path)
if not local_file_path:
print(f"Error: '{file_path}' not found in repository.")
return None

try:
return commit.tree[local_file_path].data_stream.read().decode('utf-8')
except Exception:
print(f"Error: '{local_file_path}' not found at commit '{crash_revision}'.")
print(f"Error: '{file_path}' not found at commit '{crash_revision}'.")
return None


Expand Down

0 comments on commit ddf5e51

Please sign in to comment.