-
-
Notifications
You must be signed in to change notification settings - Fork 33.6k
Gh-142174: Explicitly disallow _as_parameter_ returning tuples
#142175
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
base: main
Are you sure you want to change the base?
Conversation
…t conversions in ctypes and add a test for the `TypeError` it raises.
|
Most changes to Python require a NEWS entry. Add one using the blurb_it web app or the blurb command-line tool. If this change has little impact on Python users, wait for a maintainer to apply the |
_as_parameter_ returning tuples for default conversions in ctypes and add a test for the TypeError it raises._as_parameter_ returning tuples for default conversions in ctypes and add a test for the TypeError it raises.
_as_parameter_ returning tuples for default conversions in ctypes and add a test for the TypeError it raises._as_parameter_ returning tuples for default conversions in ctypes and add a test for the TypeError it raises.
_as_parameter_ returning tuples for default conversions in ctypes and add a test for the TypeError it raises._as_parameter_ returning tuples
ZeroIntensity
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please don't use LLMs to generate pull requests. See our AI policy.
| if (tstate && tstate->interp) { | ||
| REFTOTAL(tstate->interp) += n; | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This looks unrelated to this change and is incorrect. tstate and tstate->interp are never NULL here.
|
|
||
| __attribute__((constructor)) void load_dyld_shared_cache_contains_path(void) { | ||
| libsystem_b_handle = dlopen("/usr/lib/libSystem.B.dylib", RTLD_LAZY); | ||
| libsystem_b_handle = dlopen("/usr/lib/libSystem.B.dylib", RTLD_LAZY | RTLD_GLOBAL); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hmm, this looks unrelated as well.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please don't put your name in the filename. If you'd like to get credit, you can add something like "Patch by Your Name." at the end of the entry.
| @@ -0,0 +1,2 @@ | |||
|
|
|||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Extra newline.
| def test_as_parameter_tuple(self): | ||
| class Dangerous(object): | ||
| @property | ||
| def _as_parameter_(self): | ||
| return ('i', 42) | ||
|
|
||
| func = CDLL(_ctypes_test.__file__)._testfunc_p_p | ||
| func.restype = c_int | ||
| # func.argtypes = [c_void_p] # Do not set argtypes to force default conversion | ||
|
|
||
| # Should raise ArgumentError because tuples are not supported in default conversion | ||
| with self.assertRaisesRegex(ArgumentError, "argument 1: TypeError: Don't know how to convert parameter 1"): | ||
| func(Dangerous(), 0) | ||
|
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This test already passes on main.
|
A Python core developer has requested some changes be made to your pull request before we can consider merging it. If you could please address their requests along with any other requests in other reviews from core developers that would be appreciated. Once you have made the requested changes, please leave a comment on this pull request containing the phrase And if you don't make the requested changes, you will be poked with soft cushions! |
Remove misleading comment about tuple support in
as_parameterand add regression testModules/_ctypes/callproc.ccontained a comment (markedXXX) stating thatas_parameterallows constructing arbitrary tuples and passing them, describing this convention as "dangerous".Analysis confirms that
ctypesdoes not support returning tuples fromas_parameterfor default conversions. Attempting to do so raises aTypeError(wrapped in anArgumentError), meaning the described security risk does not exist in the current codebase.This PR includes:
Modules/_ctypes/callproc.cto avoid confusion.test_as_parameter_tuple, inLib/test/test_ctypes/test_parameters.pyto verify that returning a tuple correctly raises aTypeError, ensuring this unsafe behavior remains disabled.