[New-bugs-announce] [issue1523] xdrlib fails to detect overflow (struct bug?)

Jack Lloyd report at bugs.python.org
Thu Nov 29 18:15:12 CET 2007

New submission from Jack Lloyd:

The XDR format requires integers to fit into 4 byte values. However (at
least on x86-64) xdrlib will silently accept (and truncate) values
larger than this (up to 2**64-1). Taking a (very brief) look at the
xdrlib code, it appears this is actually a problem in the struct module,
but I don't have the time (or interest) to trace through the _struct
module code.

An example on an x86-64 machine (Python 2.4.3) of encoding 2**32 (which
will not fit in an XDR field) being silently truncated:

$ ./xdr.py 
4294967296 -> 00000000 -> 0

An example of struct itself not detecting overflow:

>>> struct.pack("!I", 2**32)

struct.pack will only throw an overflow error if a value >= 2**64 is
used, even if it is encoding into a field that is much smaller.

components: Extension Modules
files: xdr.py
messages: 57939
nosy: lloyd
severity: normal
status: open
title: xdrlib fails to detect overflow (struct bug?)
type: behavior
versions: Python 2.4
Added file: http://bugs.python.org/file8825/xdr.py

Tracker <report at bugs.python.org>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: xdr.py
Type: application/octet-stream
Size: 417 bytes
Desc: not available
Url : http://mail.python.org/pipermail/new-bugs-announce/attachments/20071129/48bdbeb1/attachment.obj 

More information about the New-bugs-announce mailing list