Skip to content

hint to how to suppress decompressionbomb warnings #235

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 1 commit into from
Jan 25, 2017

Conversation

t-animal
Copy link
Contributor

The warnings could also be suppressed by wrapping PILImage.open() in Image with warnings.catch_warnings:

with warnings.catch_warnings():
    img = PILImage.open(...)

However that is not defined behaviour for multithreading: https://docs.python.org/2/library/warnings.html#temporarily-suppressing-warnings

@saimn
Copy link
Owner

saimn commented Jan 20, 2017

Using catch_warnings for the PILImage.open calls seems more sensible, it should also catch only the DecompressionBombWarning (warnings.simplefilter('ignore', Image.DecompressionBombWarning)).
I could also be a good idea to log a message when this happens, not sure about the level, DEBUG or INFO ?

@t-animal
Copy link
Contributor Author

I updated the filter.

I don't know if it's a good idea to wrap all PILImage.open calls in a catch_warnings context, as the documentation states that "If two or more threads use the catch_warnings context manager at the same time, the behavior is undefined". I guess at least generate_image is called in a multithreading environment.

By default, there is a log message, because the warnings module logs to stderr.

@saimn
Copy link
Owner

saimn commented Jan 20, 2017

Sigal is using multiple processes, not threads, so it should be fine.

By default, there is a log message, because the warnings module logs to stderr.

But not if you catch the warning. So my idea is that it should still be possible to see the warning message in debug/verbose mode, but not in the normal mode.

@t-animal
Copy link
Contributor Author

Unfortunately one cannot use the context manager to filter for the category, so I did that manually. I logged the warnings to info, as it might be interesting to a user, not just a developer.

@saimn saimn merged commit c2621dc into saimn:master Jan 25, 2017
@saimn
Copy link
Owner

saimn commented Jan 25, 2017

Unfortunately one cannot use the context manager to filter for the category, so I did that manually

Yep, right. Thanks !

@t-animal t-animal deleted the warnings_ignore branch January 26, 2017 16:50
@saimn saimn added this to the 1.4.0 milestone Feb 5, 2017
kontza pushed a commit to kontza/sigal that referenced this pull request Aug 28, 2020
hint to how to suppress decompressionbomb warnings
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.

2 participants