Open aclark4life opened 8 months ago
From IRC,
bjs: aclark: if you have tests, and you run those tests without -O0, and the tests run code with
assert
statements in it, then you should be passing the bar as the text is written.cchianel: aclark, see https://docs.python.org/3/using/cmdline.html#cmdoption-O
bjs: aclark: if your test environment runs Python with -O then my reading of that text would say you wouldn't meet the requirement, for example. As that would disable the assertion checks. I think it'd be more debatable whether the sprinkling of
if ...: raise ...
checks that pillow undoubtedly has would also count towards this requirementbjs: I would argue yes, but others may dissent :)
bjs: aclark: I think the rationale is clear though: they want you to make the code do a bunch of extra safety/sanity checks at runtime while it runs the tests (separate to the test case itself), and it's okay if these checks are only ran during testing and users don't get them (or are disabled) when they import the library.
Thanks IRC folks! And because I can't help myself, here's what ChatGPT thinks
from PIL import Image
import os
# Define a configuration variable to enable dynamic analysis assertions
dynamic_analysis_enable_assertions = True
# Define a function to perform dynamic analysis
def perform_dynamic_analysis(image_path):
if dynamic_analysis_enable_assertions:
# Perform assertions or other checks during dynamic analysis
assert os.path.exists(image_path), "Image file does not exist"
assert os.path.splitext(image_path)[1].lower() in ['.jpg', '.jpeg', '.png'], "Unsupported image format"
# Load the image using Pillow
image = Image.open(image_path)
# Further processing...
# Example: image.show()
# Example usage
if __name__ == "__main__":
# Path to the image file
image_path = "example_image.jpg"
# Perform dynamic analysis on the image
perform_dynamic_analysis(image_path)
bjs: aclark: I don't know what ChatGPT was smoking SnoopJ: reddit, probably Jefren laughs out loud
@python-pillow/pillow-team Can anyone point me in some tangible direction to try to do some work on this one? Thank you!
You could see how other Python projects have handled it:
We are only one best practice away from transitioning our OpenSSF badge from in-progress to passing! Thanks @hugovk and @radarhere for re-raising this in #7610.
I remember discussing this in the past and if I recall correctly, we never gained a consensus. At a glance, I'm not sure I fully understand what the challenges to declaring this "met" are. Here's the best practice details:
So, ignoring the "using in production" aspect, what does "use a configuration for at least some dynamic analysis which enables many assertions" require in our case?
Are we talking specifically about
assert
statements and if so do any of these count? Assuming some are security related, maybe we just need an "on/off". (Actually I assume none are security related… and when I say security-related I mean corresponding to a CVE fix.)