Commit 72cf7914 by Ned Batchelder

Set the default memory limit to 0 while we straighten out how settings are handled.

parent 07494f16
...@@ -79,6 +79,7 @@ Other details here that depend on your configuration: ...@@ -79,6 +79,7 @@ Other details here that depend on your configuration:
<SANDENV>/bin/python { <SANDENV>/bin/python {
#include <abstractions/base> #include <abstractions/base>
#include <abstractions/python>
<SANDENV>/** mr, <SANDENV>/** mr,
# If you have code that the sandbox must be able to access, add lines # If you have code that the sandbox must be able to access, add lines
......
...@@ -72,8 +72,8 @@ LIMITS = { ...@@ -72,8 +72,8 @@ LIMITS = {
"CPU": 1, "CPU": 1,
# Real time, defaulting to 1 second. # Real time, defaulting to 1 second.
"REALTIME": 1, "REALTIME": 1,
# Total process virutal memory, in bytes, defaulting to 30 Mb. # Total process virutal memory, in bytes, defaulting to unlimited.
"VMEM": 30000000, "VMEM": 0,
} }
...@@ -94,7 +94,7 @@ def set_limit(limit_name, value): ...@@ -94,7 +94,7 @@ def set_limit(limit_name, value):
in real time. The default is 1 second. in real time. The default is 1 second.
* `"VMEM"`: the total virtual memory available to the jailed code, in * `"VMEM"`: the total virtual memory available to the jailed code, in
bytes. The default is 30 Mb. bytes. The default is 0 (no memory limit).
Limits are process-wide, and will affect all future calls to jail_code. Limits are process-wide, and will affect all future calls to jail_code.
Providing a limit of 0 will disable that limit. Providing a limit of 0 will disable that limit.
......
...@@ -120,20 +120,21 @@ class TestLimits(JailCodeHelpers, unittest.TestCase): ...@@ -120,20 +120,21 @@ class TestLimits(JailCodeHelpers, unittest.TestCase):
super(TestLimits, self).tearDown() super(TestLimits, self).tearDown()
def test_cant_use_too_much_memory(self): def test_cant_use_too_much_memory(self):
# This will fail (default is 30Mb) # This will fail after setting the limit to 30Mb.
set_limit('VMEM', 30000000)
res = jailpy(code="print len(bytearray(50000000))") res = jailpy(code="print len(bytearray(50000000))")
self.assertEqual(res.stdout, "") self.assertEqual(res.stdout, "")
self.assertNotEqual(res.status, 0) self.assertNotEqual(res.status, 0)
def test_changing_vmem_limit(self): def test_changing_vmem_limit(self):
# Up the limit, it will succeed # Up the limit, it will succeed.
set_limit('VMEM', 600000000) set_limit('VMEM', 60000000)
res = jailpy(code="print len(bytearray(50000000))") res = jailpy(code="print len(bytearray(50000000))")
self.assertEqual(res.stdout, "50000000\n") self.assertEqual(res.stdout, "50000000\n")
self.assertEqual(res.status, 0) self.assertEqual(res.status, 0)
def test_disabling_vmem_limit(self): def test_disabling_vmem_limit(self):
# Disable the limit, it will succeed # Disable the limit, it will succeed.
set_limit('VMEM', 0) set_limit('VMEM', 0)
res = jailpy(code="print len(bytearray(50000000))") res = jailpy(code="print len(bytearray(50000000))")
self.assertEqual(res.stdout, "50000000\n") self.assertEqual(res.stdout, "50000000\n")
......
...@@ -12,13 +12,12 @@ class JsonSafeTest(unittest.TestCase): ...@@ -12,13 +12,12 @@ class JsonSafeTest(unittest.TestCase):
""" """
# Unicode surrogate values # Unicode surrogate values
SURROGATE_RANGE = range(55296, 57344) SURROGATE_RANGE = range(0xD800, 0xE000)
def test_unicode(self): def test_unicode(self):
""" """
Test that json_safe() handles non-surrogate unicode values Test that json_safe() handles non-surrogate unicode values
""" """
# Try a few non-ascii UTF-16 characters # Try a few non-ascii UTF-16 characters
for unicode_char in [unichr(512), unichr(2**8-1), unichr(2**16-1)]: for unicode_char in [unichr(512), unichr(2**8-1), unichr(2**16-1)]:
...@@ -34,26 +33,22 @@ class JsonSafeTest(unittest.TestCase): ...@@ -34,26 +33,22 @@ class JsonSafeTest(unittest.TestCase):
""" """
Test that json_safe() excludes surrogate unicode values Test that json_safe() excludes surrogate unicode values
""" """
# Try surrogate unicode values # Try surrogate unicode values
for code in self.SURROGATE_RANGE: for code in self.SURROGATE_RANGE:
unicode_char = unichr(code) unicode_char = unichr(code)
# Try it as a dictionary value # Try it as a dictionary value
result = json_safe({'test': unicode_char}) result = json_safe({'test': unicode_char})
self.assertFalse('test' in result) self.assertNotIn('test', result)
def test_surrogate_unicode_keys(self): def test_surrogate_unicode_keys(self):
""" """
Test that json_safe() excludes surrogate unicode keys Test that json_safe() excludes surrogate unicode keys
""" """
# Try surrogate unicode values # Try surrogate unicode values
for code in self.SURROGATE_RANGE: for code in self.SURROGATE_RANGE:
unicode_char = unichr(code) unicode_char = unichr(code)
# Try it is a dictionary key # Try it is a dictionary key
result = json_safe({unicode_char: 'test'}) result = json_safe({unicode_char: 'test'})
self.assertFalse(unicode_char in result) self.assertNotIn(unicode_char, result)
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment