Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
C
codejail
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
edx
codejail
Commits
72cf7914
Commit
72cf7914
authored
May 23, 2013
by
Ned Batchelder
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Set the default memory limit to 0 while we straighten out how settings are handled.
parent
07494f16
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
12 additions
and
15 deletions
+12
-15
README.rst
+1
-0
codejail/jail_code.py
+3
-3
codejail/tests/test_jail_code.py
+5
-4
codejail/tests/test_json_safe.py
+3
-8
No files found.
README.rst
View file @
72cf7914
...
@@ -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
...
...
codejail/jail_code.py
View file @
72cf7914
...
@@ -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"
:
3000000
0
,
"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.
...
...
codejail/tests/test_jail_code.py
View file @
72cf7914
...
@@ -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'
,
60000000
0
)
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
"
)
...
...
codejail/tests/test_json_safe.py
View file @
72cf7914
...
@@ -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
.
assert
False
(
'test'
in
result
)
self
.
assert
NotIn
(
'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
.
assert
False
(
unicode_char
in
result
)
self
.
assert
NotIn
(
unicode_char
,
result
)
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment