CodeGrade / hourglass

Web-based exam server.
13 stars 4 forks source link

Uploading an exam-references zip file from Mac causes Err500 #422

Open blerner opened 1 year ago

blerner commented 1 year ago

If the zip contains a __MACOSX folder, the files may "contain invalid Unicode", when treated as text, which causes an uncaught exception at https://github.com/CodeGrade/hourglass/blob/master/app/graphql/mutations/change_exam_version_details.rb#L55:

log/production.log:289:I, [2022-10-10T06:57:58.889629 #97816]  INFO -- : [1bd34938-7d6a-4c02-b09b-7a33a3748cb8] Completed 500 Internal Server Error in 17ms (ActiveRecord: 2.9ms | Allocations: 7130)
log/production.log:290:F, [2022-10-10T06:57:58.890805 #97816] FATAL -- : [1bd34938-7d6a-4c02-b09b-7a33a3748cb8]
log/production.log:291:[1bd34938-7d6a-4c02-b09b-7a33a3748cb8] ActiveRecord::StatementInvalid (PG::UntranslatableCharacter: ERROR:  unsupported Unicode escape sequence
log/production.log:295:[1bd34938-7d6a-4c02-b09b-7a33a3748cb8]
log/production.log:296:[1bd34938-7d6a-4c02-b09b-7a33a3748cb8] app/graphql/mutations/change_exam_version_details.rb:55:in `block in resolve'
log/production.log:297:[1bd34938-7d6a-4c02-b09b-7a33a3748cb8] app/graphql/mutations/change_exam_version_details.rb:29:in `resolve'
log/production.log:298:[1bd34938-7d6a-4c02-b09b-7a33a3748cb8] app/graphql/hourglass_schema.rb:56:in `execute'

We need to protect that call more carefully, and probably also reject the __MACOSX folder more aggressively.