Skip to content

ENH: Create gzip header deterministically by default #1024

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

Merged
merged 8 commits into from
Jun 25, 2021

Conversation

effigies
Copy link
Member

@effigies effigies commented Jun 4, 2021

As discussed in #1023, we currently allow gzip.GzipFile to set the gzip header as it will, including filename and mtime fields. This means that files with identical unzipped contents and compression levels have different gzipped representations, which is not ideal for verifying sources of non-determinism in a complex workflow.

This PR attempts to balance sensible default behaviors with user control. It changes the default mtime from time.time() to 0, while allowing users to set the mtime as an argument to Opener().

It removes the behavior of setting the original filename in the gzip header. In a medical imaging context, the original filenames may include PHI (e.g., subject name, scan date, etc) that will follow the file through renames unless the file is rewritten entirely. A flag to preserve the old behavior does not seem worth the effort.

Fixes #1023.

@effigies
Copy link
Member Author

effigies commented Jun 4, 2021

@yarikoptic @ltetrel Would either of you care to review?

@codecov
Copy link

codecov bot commented Jun 4, 2021

Codecov Report

Merging #1024 (ff5efe4) into master (dd3fae3) will decrease coverage by 0.15%.
The diff coverage is 100.00%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master    #1024      +/-   ##
==========================================
- Coverage   92.26%   92.10%   -0.16%     
==========================================
  Files         100      100              
  Lines       12201    12205       +4     
  Branches     2134     2136       +2     
==========================================
- Hits        11257    11242      -15     
- Misses        616      630      +14     
- Partials      328      333       +5     
Impacted Files Coverage Δ
nibabel/openers.py 93.16% <100.00%> (-2.42%) ⬇️
nibabel/pydicom_compat.py 61.53% <0.00%> (-30.77%) ⬇️
nibabel/volumeutils.py 92.22% <0.00%> (-1.30%) ⬇️
nibabel/viewers.py 95.49% <0.00%> (-0.65%) ⬇️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update dd3fae3...ff5efe4. Read the comment docs.

Copy link
Member

@yarikoptic yarikoptic left a comment

Choose a reason for hiding this comment

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

Looks great, thank you @effigies !!!

@effigies
Copy link
Member Author

Thanks for the review.

@effigies effigies merged commit ea68c4e into nipy:master Jun 25, 2021
@effigies effigies deleted the fix/gzip_compression_options branch June 25, 2021 19:40
@kousu
Copy link

kousu commented Nov 20, 2021

This is great! Thank you for being proactive about squashing the indeterminism/data leakage.

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.

Setting gzip mtime to zero on image save
3 participants