Skip to content

Commit

Permalink
assume no unicode if no source code is available
Browse files Browse the repository at this point in the history
  • Loading branch information
bohendo committed Feb 5, 2025
1 parent 3404b76 commit ef3bab1
Showing 1 changed file with 11 additions and 6 deletions.
17 changes: 11 additions & 6 deletions slither/core/source_mapping/source_mapping.py
Original file line number Diff line number Diff line change
Expand Up @@ -150,9 +150,10 @@ def _compute_line(
return list(range(start_line, end_line + 1)), starting_column, ending_column


# pylint: disable=too-many-locals
def _convert_source_mapping(
offset: str, compilation_unit: "SlitherCompilationUnit"
) -> Source: # pylint: disable=too-many-locals
) -> Source:
"""
Convert a text offset to a real offset
see https://solidity.readthedocs.io/en/develop/miscellaneous.html#source-mappings
Expand Down Expand Up @@ -186,11 +187,15 @@ def _convert_source_mapping(
filename: Filename = compilation_unit.core.crytic_compile.filename_lookup(filename_used)
is_dependency = compilation_unit.core.crytic_compile.is_dependency(filename.absolute)

# convert byte-offset indicies to char-offset
source_code = compilation_unit.core.source_code[filename.absolute]
s = int(len(source_code.encode("utf-8")[:s_bytes].decode("utf-8")))
l = int(len(source_code.encode("utf-8")[s_bytes : s_bytes + l_bytes].decode("utf-8")))
f = int(f)
if filename.absolute in compilation_unit.core.source_code:
# convert byte-offset indicies to char-offset
source_code = compilation_unit.core.source_code[filename.absolute]
s = int(len(source_code.encode("utf-8")[:s_bytes].decode("utf-8")))
l = int(len(source_code.encode("utf-8")[s_bytes : s_bytes + l_bytes].decode("utf-8")))
else:
# no source code is available, hopefully the source code doesn't contain unicode
s = int(s_bytes)
l = int(l_bytes)

(lines, starting_column, ending_column) = _compute_line(compilation_unit, filename, s, l)

Expand Down

0 comments on commit ef3bab1

Please sign in to comment.