classification
Title: exceeding obscure weakproxy bug
Type: behavior Stage: needs patch
Components: Interpreter Core Versions: Python 3.2, Python 3.1
process
Status: open Resolution:
Dependencies: Superseder:
Assigned To: Nosy List: ajaksu2, amaury.forgeotdarc, mwh, orsenthil, pitrou
Priority: low Keywords:

Created on 2004-11-29 16:10 by mwh, last changed 2011-01-24 05:07 by orsenthil.

Messages (5)
msg60608 - (view) Author: Michael Hudson (mwh) (Python committer) Date: 2004-11-29 16:10
Broadly speaking, this line (488 in today's CVS) in
Python/weakref.c isn't right:

WRAP_UNARY(proxy_int, PyNumber_Int)

because PyNumber_Int will convert from a string
argument.  You can "exploit" this like so:

class U(unicode): pass

u = U("1")
try:
    range(u)
except TypeError:
    print "raised, good"
else:
    print "didn't raise, bad"
import _weakref

try:
    range(_weakref.proxy(u))
except TypeError:
    print "raised, good"
else:
    print "didn't raise, bad"

(prints

raised, good
didn't raise, bad

for me).  I think the fix is PyNumber_Int ->
PyInt_AsLong, but haven't checked that.
msg82168 - (view) Author: Daniel Diniz (ajaksu2) Date: 2009-02-15 20:41
Confirmed with rev69546.
msg125274 - (view) Author: Antoine Pitrou (pitrou) * (Python committer) Date: 2011-01-04 01:30
Works fine under 3.x.
msg125337 - (view) Author: Amaury Forgeot d'Arc (amaury.forgeotdarc) * (Python committer) Date: 2011-01-04 16:24
It's not fixed. range() now uses the tp_index slot, in weakrefs this becomes:
    WRAP_UNARY(proxy_index, PyNumber_Index)
and indeed PyNumber_Index does not accept strings.

But try with time.sleep() instead; here the line
    WRAP_UNARY(proxy_float, PyNumber_Float)
is involved:


import _weakref, time

class U(str): pass
u = U("1")

try:
    time.sleep(u)
except TypeError:
    print("raised, good")
else:
    print("didn't raise, bad")

try:
    time.sleep(_weakref.proxy(u))
except TypeError:
    print("raised, good")
else:
    print("didn't raise, bad")
msg126916 - (view) Author: Senthil Kumaran (orsenthil) * (Python committer) Date: 2011-01-24 05:07
I find this problem with 3.x and not with 2.x codeline
History
Date User Action Args
2011-01-24 05:07:00orsenthilsetnosy: + orsenthil

messages: + msg126916
versions: + Python 3.1, Python 3.2, - Python 2.7
2011-01-04 16:24:07amaury.forgeotdarcsetnosy: + amaury.forgeotdarc
messages: + msg125337
2011-01-04 01:30:59pitrousetversions: - Python 3.1, Python 3.2
nosy: + pitrou

messages: + msg125274

stage: test needed -> needs patch
2010-08-19 18:38:12BreamoreBoysetversions: + Python 3.1, Python 2.7, Python 3.2, - Python 2.6
2009-02-15 20:41:45ajaksu2settype: behavior
stage: test needed
messages: + msg82168
nosy: + ajaksu2
versions: + Python 2.6, - Python 2.4
2004-11-29 16:10:35mwhcreate