Skip to content

Don't crash on non UTF-8 input files in the modified file checks.#392

Open
Tagl wants to merge 3 commits intoKattis:masterfrom
Tagl:fix_crash_non_utf8
Open

Don't crash on non UTF-8 input files in the modified file checks.#392
Tagl wants to merge 3 commits intoKattis:masterfrom
Tagl:fix_crash_non_utf8

Conversation

@Tagl
Copy link
Contributor

@Tagl Tagl commented Mar 1, 2026

Closes #390

Copy link
Contributor

@gkreitz gkreitz left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the bug report and fix! I think one of the try-catch:es is probably not needed, unless I'm missing something?


with open(file_name, 'wb') as f:
f.write(modifier(infile_data).encode('utf8'))
try:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this try-catch actually needed? It looks like all we're doing is encoding a python string as utf-8, and I think that's always safe (and if it can fail, I would expect a UnicodeEncodeError).

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You're right. Should change to UnicodeEncodeError. It was just defensive programming to avoid a similar situation on write.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changed

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think we need to be that defensive. Python strings internally are unicode, and there should never be a unicode code point that utf-8 can't encode. UnicodeEncodeError would be applicable if we didn't specify an encoding (so it used locale), or if we went old-school iso-8859-x.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I removed it

@Tagl
Copy link
Contributor Author

Tagl commented Mar 2, 2026 via email

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.

Modified inputs cause validation to fail

2 participants