Don't crash on non UTF-8 input files in the modified file checks.#392
Don't crash on non UTF-8 input files in the modified file checks.#392Tagl wants to merge 3 commits intoKattis:masterfrom
Conversation
gkreitz
left a comment
There was a problem hiding this comment.
Thanks for the bug report and fix! I think one of the try-catch:es is probably not needed, unless I'm missing something?
problemtools/verifyproblem.py
Outdated
|
|
||
| with open(file_name, 'wb') as f: | ||
| f.write(modifier(infile_data).encode('utf8')) | ||
| try: |
There was a problem hiding this comment.
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).
There was a problem hiding this comment.
You're right. Should change to UnicodeEncodeError. It was just defensive programming to avoid a similar situation on write.
There was a problem hiding this comment.
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.
|
Good with me. I just need this updated on Kattis ASAP for our contest, so
as long as it works with image files as input then I don't mind.
…On Mon, Mar 2, 2026, 11:34 Gunnar Kreitz ***@***.***> wrote:
***@***.**** commented on this pull request.
------------------------------
In problemtools/verifyproblem.py
<#392 (comment)>:
> continue
- with open(file_name, 'wb') as f:
- f.write(modifier(infile_data).encode('utf8'))
+ try:
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.
—
Reply to this email directly, view it on GitHub
<#392 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AB2ZBKXM7SXDGLTY44K5GC34OVWULAVCNFSM6AAAAACWDLPSMSVHI2DSMVQWIX3LMV43YUDVNRWFEZLROVSXG5CSMV3GSZLXHMZTQNZVGYZTGMRXGQ>
.
You are receiving this because you authored the thread.Message ID:
***@***.***>
|
Closes #390