Skip to content

Allow savefig to save SVGs on FIPS enabled systems #18192 #18193

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 2 commits into from
Aug 7, 2020

Conversation

daytonb
Copy link
Contributor

@daytonb daytonb commented Aug 6, 2020

PR Summary

This pull request resolves #18192.

If you use a FIPS (Federal Information Processing Standards) enabled system, then you cannot use plt.savefig to save an image in SVG format. This is because the RenderSVG._make_id method takes the first 10 characters of a hashlib.md5 digest of entries in the SVG as the ID for entries in the SVG file.

The Python docs for hashlib includes the following note:

Constructors for hash algorithms that are always present in this module are sha1(), sha224(), sha256(), sha384(), sha512(), blake2b(), and blake2s(). md5() is normally available as well, though it may be missing if you are using a rare “FIPS compliant” build of Python.

PR Checklist

  • [na ] Has Pytest style unit tests
    - Not sure if this is applicable to my change
  • Code is Flake 8 compliant
  • [na] New features are documented, with examples if plot related
  • Documentation is sphinx and numpydoc compliant
  • [na] Added an entry to doc/users/next_whats_new/ if major new feature (follow instructions in README.rst there)
    - Not a major feature
  • Documented in doc/api/next_api_changes/* if API changed in a backward-incompatible way

Copy link
Member

@dstansby dstansby left a comment

Choose a reason for hiding this comment

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

Seems like a reasonable approach. Is this injected into the .svg files? If so it would be good to add a quick note to doc/api/next_api_changes/behavior to say that the contents will be slightly different, just in case there is anybody comparing the hashes of matplotlib generated .svg files.

@daytonb
Copy link
Contributor Author

daytonb commented Aug 6, 2020 via email

@dopplershift dopplershift added this to the v3.4.0 milestone Aug 7, 2020
@daytonb
Copy link
Contributor Author

daytonb commented Aug 7, 2020

Alright I've added a file to the doc/api/next_api_changes/behavior. Let me know if the description seems unclear and needs tweaking.

@daytonb
Copy link
Contributor Author

daytonb commented Aug 7, 2020

I re-wrote the behavior change note to no longer reference the private method. I was also previously getting an error from the circleci doc tests that I think was from the warnings Sphinx gave about my references to hashlib.md5 and RenderSVG._make_id. The warnings said that Sphinx couldn't find these pyobjs to link to them. Obviously I removed the reference to RenderSVG._make_id so that won't be a problem any more, but I also reworded my note about hashlib.md5 to avoid having to do a intersphinx reference.

Copy link
Member

@jklymak jklymak left a comment

Choose a reason for hiding this comment

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

This seems fine to me. I don't know that it really needs an API change note - the origin of the hash is just an implementation detail of the unique ID, and its not like the user needs to know that. But, I guess it doesn't hurt.

@jkseppan jkseppan merged commit 9b7f94f into matplotlib:master Aug 7, 2020
@jkseppan
Copy link
Member

jkseppan commented Aug 7, 2020

Thanks @daytonb!

@daytonb
Copy link
Contributor Author

daytonb commented Aug 7, 2020

It's been a pleasure!

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.

Cannot save SVG file with FIPS compliant Python
6 participants