[New-bugs-announce] [issue43824] array.array.__deepcopy__() accepts a parameter of any type

MingZhe Hu report at bugs.python.org
Mon Apr 12 23:00:23 EDT 2021


New submission from MingZhe Hu <humingzhework at 163.com>:

The C implementation of foreign function array.array.__deepcopy__() is declared as follows:

https://github.com/python/cpython/blob/d9151cb45371836d39b6d53afb50c5bcd353c661/Modules/arraymodule.c#L855

The second argument is unused in the function body.

However, corresponding PyMethodDef is declared with `METH_O` flag, meaning one parameter should be passed to array.array.__deepcopy__() from the Python side:

https://github.com/python/cpython/blob/d9151cb45371836d39b6d53afb50c5bcd353c661/Modules/clinic/arraymodule.c.h#L30

This makes the following code legal:

```
import array
a = array.array('b',  [ord('g')])
a.__deepcopy__('str')
a.__deepcopy__(1)
a.__deepcopy__([1,'str'])
```

A parameter of ANY type can be passed to the foreign function, without effect on its semantic.

These code are clinic generated, and similar problems can be found for more foreign functions.

----------
components: Argument Clinic, Extension Modules
messages: 390918
nosy: Elaphurus, larry
priority: normal
severity: normal
status: open
title: array.array.__deepcopy__() accepts a parameter of any type
type: behavior
versions: Python 3.10, Python 3.6, Python 3.7, Python 3.8, Python 3.9

_______________________________________
Python tracker <report at bugs.python.org>
<https://bugs.python.org/issue43824>
_______________________________________


More information about the New-bugs-announce mailing list