Skip to content

Conversation

@stevennevins
Copy link

Fix source code corruption when slither-mutate processes Solidity files containing Unicode characters (e.g., arrow symbols, non-ASCII comments).

Example

// → Unicode arrow
contract Counter {
    function increment() public {
        number++;
    }
}

The arrow is 3 bytes but 1 character. This 2-byte difference causes mutations to be applied at wrong positions.

Without fix - garbage output:

nurevert()
fufunction setNumber
nu++number

With fix - correct mutations:

revert()
function setNumber
++number

…lations

Solc reports source locations as byte offsets, but the mutator code was
using Python string indexing which operates on character counts. For
files with multi-byte Unicode characters (e.g., Japanese comments),
this caused mutations to be applied at wrong positions.

- Change test_patch() to read/write files in binary mode
- Fix apply_patch() offset calculation to use byte length
@stevennevins stevennevins force-pushed the fix/mutator-unicode-byte-offsets branch from 4d70812 to e5d2efa Compare December 8, 2025 13:46
@stevennevins stevennevins marked this pull request as ready for review December 11, 2025 21:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant