Skip to content

Commit

Permalink
Fix oss-fuzz + exporter error
Browse files Browse the repository at this point in the history
  • Loading branch information
another-rex committed Nov 27, 2024
1 parent 17e53d8 commit d674e1d
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 8 deletions.
14 changes: 9 additions & 5 deletions docker/exporter/exporter.py
Original file line number Diff line number Diff line change
Expand Up @@ -102,16 +102,20 @@ def _export_ecosystem_to_bucket(self, ecosystem: str, work_dir: str):
files_to_zip = []

@ndb.tasklet
def _export_to_file_and_zipfile(bug):
def _export_to_file_and_zipfile(bug: osv.Bug):
"""Write out a bug record to both a single file and the zip file."""
if not bug.public or bug.status == osv.BugStatus.UNPROCESSED:
return

file_path = os.path.join(ecosystem_dir, bug.id() + '.json')
vulnerability = yield bug.to_vulnerability_async(include_source=True)
osv.write_vulnerability(vulnerability, file_path)
try:
file_path = os.path.join(ecosystem_dir, bug.id() + '.json')
vulnerability = yield bug.to_vulnerability_async(include_source=True)
osv.write_vulnerability(vulnerability, file_path)

files_to_zip.append(file_path)
files_to_zip.append(file_path)
except Exception:
logging.error('Failed to export bug: "%s"', bug.id())
raise

# This *should* pause here until
# all the exports have been written to disk.
Expand Down
2 changes: 1 addition & 1 deletion osv/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -503,7 +503,7 @@ def _pre_put_hook(self): # pylint: disable=arguments-differ
if not self.key: # pylint: disable=access-member-before-definition
source_repo = get_source_repository(self.source)
if not source_repo:
raise ValueError(f'Invalid source {self.source}')
raise ValueError(f'{self.db_id} has invalid source {self.source}')

if source_repo.db_prefix and not any(
self.db_id.startswith(prefix) for prefix in source_repo.db_prefix):
Expand Down
4 changes: 2 additions & 2 deletions osv/sources.py
Original file line number Diff line number Diff line change
Expand Up @@ -303,7 +303,7 @@ def push_source_changes(repo,
return False

# Success, commit and try pushing again.
tree = repo.index.write_tree()
tree = repo.index.write_tree()
repo.create_commit(repo.head.name, commit.author, commit.author,
commit.message, tree, [repo.head.peel().id])
repo.state_cleanup()
Expand Down Expand Up @@ -334,7 +334,7 @@ def sha256_bytes(data):
def source_path(source_repo, bug):
"""Get the source path for an osv.Bug."""
source_name, source_id = parse_source_id(bug.source_id)
if source_name == 'oss-fuzz':
if source_name == 'oss-fuzz' and len(bug.project) > 0:
path = os.path.join(bug.project[0], bug.id() + source_repo.extension)
if source_repo.directory_path:
path = os.path.join(source_repo.directory_path, path)
Expand Down

0 comments on commit d674e1d

Please sign in to comment.