Skip to content

Commit

Permalink
Merge pull request #742 from kobotoolbox/hotfix-zip-exports
Browse files Browse the repository at this point in the history
Disable seeking when writing ZIP exports
  • Loading branch information
jnm authored Jun 26, 2021
2 parents 4c5cfda + a2dbb91 commit b47d846
Showing 1 changed file with 11 additions and 0 deletions.
11 changes: 11 additions & 0 deletions onadata/libs/utils/viewer_tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -227,6 +227,17 @@ def enketo_url(form_url, id_string, instance_xml=None,
def create_attachments_zipfile(attachments, output_file=None):
if not output_file:
output_file = NamedTemporaryFile()
else:
# Disable seeking in a way understood by Python's zipfile module. See
# https://github.com/python/cpython/blob/ca2009d72a52a98bf43aafa9ad270a4fcfabfc89/Lib/zipfile.py#L1270-L1274
# This is a workaround for https://github.com/kobotoolbox/kobocat/issues/475
# and https://github.com/jschneier/django-storages/issues/566
def no_seeking(*a, **kw):
raise AttributeError(
'Seeking disabled! See '
'https://github.com/kobotoolbox/kobocat/issues/475'
)
output_file.seek = no_seeking

storage = get_storage_class()()
with zipfile.ZipFile(output_file, 'w', zipfile.ZIP_STORED, allowZip64=True) as zip_file:
Expand Down

0 comments on commit b47d846

Please sign in to comment.