-
Notifications
You must be signed in to change notification settings - Fork 1.1k
fix: handle Unicode characters correctly in mutator byte offset calculation #2832
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -92,12 +92,15 @@ def test_patch( | |
| function to verify whether each patch is caught by tests | ||
| returns: 0 (uncaught), 1 (caught), or 2 (compilation failure) | ||
| """ | ||
| with open(file, "r", encoding="utf8") as filepath: | ||
| with open(file, "rb") as filepath: | ||
| content = filepath.read() | ||
| # Perform the replacement based on the index values | ||
| replaced_content = content[: patch["start"]] + patch["new_string"] + content[patch["end"] :] | ||
| # Note: patch offsets are byte offsets from solc, so we must work with bytes | ||
| replaced_content = ( | ||
| content[: patch["start"]] + patch["new_string"].encode("utf8") + content[patch["end"] :] | ||
| ) | ||
| # Write the modified content back to the file | ||
| with open(file, "w", encoding="utf8") as filepath: | ||
| with open(file, "wb") as filepath: | ||
|
Comment on lines
+95
to
+103
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Man. I fixed a related issue in a prev PR and I thought that had us good to go wrt unicode support. But looking at this now, idk how the prev fix actually fixed anything. This is the same byte-wise indexing-against-strings bug that I was wrestling w earlier, just in a different but still critical spot. Good job finding & fixing this. |
||
| filepath.write(replaced_content) | ||
|
|
||
| if compile_generated_mutant(file, mappings): | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Subtle, the bug here would only manifest if the new_string contains unicode which I don't think it does usually. But yea, this change is correct