This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: xdrlib's pack_int generates DeprecationWarnings for negative in-range values
Type: behavior Stage: resolved
Components: Library (Lib) Versions: Python 3.1, Python 3.2, Python 3.3, Python 2.7
process
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: mark.dickinson Nosy List: dep, eric.araujo, gruszczy, mark.dickinson, python-dev
Priority: normal Keywords: patch

Created on 2010-08-26 22:05 by dep, last changed 2022-04-11 14:57 by admin. This issue is now closed.

Files
File name Uploaded Description Edit
9696.patch gruszczy, 2011-03-27 09:59 review
Messages (10)
msg115034 - (view) Author: David Powell (dep) Date: 2010-08-26 22:05
The problem is easy to reproduce:

>>> import xdrlib
>>> p = xdrlib.Packer()
>>> p.pack_int(-1)
__main__:1: DeprecationWarning: struct integer overflow masking is deprecated

The cause is xdrlib.Packer uses the same pack operation for both
signed and unsigned integers...

    def pack_uint(self, x):
        self.__buf.write(struct.pack('>L', x))

    pack_int = pack_uint

...and the unsigned struct.pack('>L', x) gags on the negative value.
msg115047 - (view) Author: Éric Araujo (eric.araujo) * (Python committer) Date: 2010-08-27 00:05
Thanks for the report. This actually raises an error with current Pythons:

2.7 traceback: File "xdrlib.py", line 54, in pack_uint
    self.__buf.write(struct.pack('>L', x))
struct.error: integer out of range for 'L' format code

(The 3.x error message is slightly less helpful: “struct.error: argument out of range”).

Would you like to make a patch for this?

Bug triage tips: 2.6 only gets security fixes, bugs are not fixed there anymore. “Extension modules” are modules written in C, like time; Python modules map to the “Library” component.
msg132302 - (view) Author: Filip Gruszczyński (gruszczy) Date: 2011-03-27 09:59
Here is a test and a patch.
msg132334 - (view) Author: Mark Dickinson (mark.dickinson) * (Python committer) Date: 2011-03-27 15:12
Patch looks good to me.  Thanks!
msg132335 - (view) Author: Roundup Robot (python-dev) (Python triager) Date: 2011-03-27 15:15
New changeset d3f9a6d7f6e4 by Mark Dickinson in branch '2.7':
Issue #9696: Fix exception incorrectly raised by xdrlib.Packer.pack_int when trying to pack a negative (in-range) integer.
http://hg.python.org/cpython/rev/d3f9a6d7f6e4
msg132337 - (view) Author: Filip Gruszczyński (gruszczy) Date: 2011-03-27 15:32
I believe this should be applied also against 3.3. I was working on this using 3.3 code base, so it is not working there too.
msg132340 - (view) Author: Mark Dickinson (mark.dickinson) * (Python committer) Date: 2011-03-27 15:35
Patience!  I'm getting there...
msg132342 - (view) Author: Filip Gruszczyński (gruszczy) Date: 2011-03-27 15:37
I'm sorry, I wasn't hurrying you. Just wanted to make sure you know.
msg132344 - (view) Author: Roundup Robot (python-dev) (Python triager) Date: 2011-03-27 15:39
New changeset bd5e821f201c by Mark Dickinson in branch '3.1':
Issue #9696: Fix exception incorrectly raised by xdrlib.Packer.pack_int when trying to pack a negative (in-range) integer.
http://hg.python.org/cpython/rev/bd5e821f201c

New changeset 391b2ddbc1b7 by Mark Dickinson in branch '3.2':
Merge #9696
http://hg.python.org/cpython/rev/391b2ddbc1b7

New changeset d9b64a86d5a7 by Mark Dickinson in branch 'default':
Merge #9696
http://hg.python.org/cpython/rev/d9b64a86d5a7
msg132345 - (view) Author: Mark Dickinson (mark.dickinson) * (Python committer) Date: 2011-03-27 15:41
> I'm sorry, I wasn't hurrying you. Just wanted to make sure you know.

No problem :-).  Thanks for the fix!
History
Date User Action Args
2022-04-11 14:57:05adminsetgithub: 53905
2011-03-27 15:41:36mark.dickinsonsetstatus: open -> closed
versions: + Python 3.3
messages: + msg132345

resolution: fixed
stage: resolved
2011-03-27 15:39:59python-devsetmessages: + msg132344
2011-03-27 15:37:05gruszczysetmessages: + msg132342
2011-03-27 15:35:31mark.dickinsonsetmessages: + msg132340
2011-03-27 15:32:42gruszczysetmessages: + msg132337
2011-03-27 15:15:29python-devsetnosy: + python-dev
messages: + msg132335
2011-03-27 15:12:37mark.dickinsonsetassignee: mark.dickinson
messages: + msg132334
2011-03-27 09:59:59gruszczysetfiles: + 9696.patch

nosy: + gruszczy
messages: + msg132302

keywords: + patch
2010-08-28 08:05:34mark.dickinsonsetnosy: + mark.dickinson
2010-08-27 00:05:56eric.araujosetversions: + Python 3.1, Python 2.7, Python 3.2, - Python 2.6
nosy: + eric.araujo

messages: + msg115047

components: + Library (Lib), - Extension Modules
2010-08-26 22:05:01depcreate