Author: Armin Rigo <[email protected]>
Branch:
Changeset: r81833:4fd739667032
Date: 2016-01-18 11:08 +0100
http://bitbucket.org/pypy/pypy/changeset/4fd739667032/
Log: test and fix for the sandboxing issue on 32-bit (test_lseek)
diff --git a/rpython/rlib/rmarshal.py b/rpython/rlib/rmarshal.py
--- a/rpython/rlib/rmarshal.py
+++ b/rpython/rlib/rmarshal.py
@@ -90,6 +90,8 @@
dumper._annenforceargs_ = [s_list_of_chars, s_obj]
def add_loader(s_obj, loader):
+ # 's_obj' should be the **least general annotation** that we're
+ # interested in, somehow
loaders.append((s_obj, loader))
def get_dumper_annotation(dumper):
@@ -187,6 +189,14 @@
r_32bits_mask = r_longlong(0xFFFFFFFF)
+def load_longlong_nonneg(loader):
+ x = load_longlong(loader)
+ if x < 0:
+ raise ValueError("expected a non-negative longlong")
+ return x
+add_loader(annmodel.SomeInteger(knowntype=r_longlong, nonneg=True),
+ load_longlong_nonneg)
+
def load_longlong(loader):
if readchr(loader) != TYPE_INT64:
raise ValueError("expected a longlong")
diff --git a/rpython/rlib/test/test_rmarshal.py
b/rpython/rlib/test/test_rmarshal.py
--- a/rpython/rlib/test/test_rmarshal.py
+++ b/rpython/rlib/test/test_rmarshal.py
@@ -190,3 +190,13 @@
assert sttuple[4] == st[4]
assert sttuple[5] == st[5]
assert len(sttuple) == 10
+
+def test_longlong():
+ # get_loader for (r_longolong, nonneg=True) used to return
+ # load_int_nonneg on 32-bit, instead of load_longlong.
+ for nonneg in [True, False]:
+ s_longlong = annmodel.SomeInteger(knowntype=r_longlong, nonneg=nonneg)
+ load = get_loader(s_longlong)
+ loader = Loader("I\x01\x23\x45\x67\x89\xab\xcd\x0e")
+ res = load(loader)
+ assert res == 0x0ecdab8967452301
_______________________________________________
pypy-commit mailing list
[email protected]
https://mail.python.org/mailman/listinfo/pypy-commit