Skip to content

Commit 57e6f5c

Browse files
Mike4751GuardianAudits
authored andcommitted
address review: size array for all filenames, raise on source ID gaps
1 parent 4a9ab22 commit 57e6f5c

File tree

1 file changed

+14
-6
lines changed

1 file changed

+14
-6
lines changed

crytic_compile/compilation_unit.py

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -198,9 +198,10 @@ def filenames_for_export(self) -> list[Filename]:
198198
if not self._source_id_to_filename:
199199
return self._filenames
200200

201-
# Build list indexed by source ID
201+
# Build list indexed by source ID; +1 because IDs are zero-indexed
202202
max_id = max(self._source_id_to_filename.keys())
203-
result: list[Filename | None] = [None] * (max_id + 1)
203+
size = max(max_id + 1, len(self._filenames))
204+
result: list[Filename | None] = [None] * size
204205

205206
for source_id, filename in self._source_id_to_filename.items():
206207
result[source_id] = filename
@@ -215,11 +216,18 @@ def filenames_for_export(self) -> list[Filename]:
215216
try:
216217
result[i] = next(unmapped_iter)
217218
except StopIteration:
218-
# No more unmapped filenames, leave as None (will be filtered)
219-
pass
219+
break
220220

221-
# Filter out None entries and return
222-
return [f for f in result if f is not None]
221+
# Gaps in the source ID sequence mean the build-info is incomplete;
222+
# exporting with shifted indices would silently produce wrong source maps
223+
gaps = [i for i, f in enumerate(result) if f is None]
224+
if gaps:
225+
raise ValueError(
226+
f"Source ID gaps at indices {gaps} — cannot produce correct sourceList. "
227+
f"This likely indicates missing sources in build-info."
228+
)
229+
230+
return result
223231

224232
def set_source_id(self, source_id: int, filename: Filename) -> None:
225233
"""Set the source ID for a filename.

0 commit comments

Comments
 (0)