summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorroot <root@andjedan.(none)>2011-08-16 08:00:46 +0430
committerroot <root@andjedan.(none)>2011-08-12 16:30:17 -0700
commit9cb5ecf6956115140521d74cea8b4191634842fd (patch)
treea5d32ba73a85965e15a8a76e634be139c35d6a86
parent9f43cfbf63b83cf02da8647c50a4c6dc523de5ad (diff)
downloadhellijudge-legacy.git-0.8.tar.gz
hellijudge-legacy.git-0.8.tar.xz
hellijudge-legacy.git-0.8.zip
Fix memory and time limit casting bugv0.8
Memory and time limit numbers should be casted from string to int or else comparison between total memory and time used by user's binary would lead judge to run user's binary with memory limit defined in pam_limits, and time limit as double as problem time limit. bug found at submission number 1402 @ HelliCode
-rw-r--r--base/config.py55
-rw-r--r--base/core.py4
-rw-r--r--base/run.py39
3 files changed, 53 insertions, 45 deletions
diff --git a/base/config.py b/base/config.py
index 2092aa5..09eb0fb 100644
--- a/base/config.py
+++ b/base/config.py
@@ -19,24 +19,41 @@
import os
PROBCONFADDR = os.getenv('PROBCONFADDR')
+INPUT_DIR = os.getenv('INPUT_DIR')
+
+class Config:
+ def __init__(self, address):
+ self.data = []
+ self.address = address
+
+ def parse(self):
+ PROBCONF = open (self.address, 'r')
+
+ self.count = int (PROBCONF.readline().strip())
+ CONFMOD = PROBCONF.readline().strip()
+
+ if CONFMOD == 'default':
+ confline = PROBCONF.readline().strip()
+ for i in range(self.count):
+ self.data.append (confline.replace ('%n', str(i)).split())
+ else:
+ for i in range(self.count):
+ confline = PROBCONF.readline()
+ self.data.append (confline.replace ('%n', str(i)).split())
+
+ PROBCONF.close()
+
+ def input_command(self, test):
+ input_command = INPUT_DIR + '/' + self.data[test][3];
+
+ if (self.data[test][0] == 'normal'):
+ input_command = 'cat ' + input_command
+ return input_command
+
+ def get_limits(self, test):
+ return [int(self.data[test][1]), int(self.data[test][2])]
def parse():
- PROBCONF = open (PROBCONFADDR, 'r')
-
- COUNT = int (PROBCONF.readline().strip())
- CONFMOD = PROBCONF.readline().strip()
-
- CONFIG = []
-
- if CONFMOD == 'default':
- confline = PROBCONF.readline().strip()
- for i in range(COUNT):
- CONFIG.append (confline.replace ('%n', str(i)).split())
- else:
- for i in range(COUNT):
- confline = PROBCONF.readline()
- CONFIG.append (confline.replace ('%n', str(i)).split())
-
- PROBCONF.close()
-
- return [COUNT, CONFIG]
+ CONFIG = Config (PROBCONFADDR)
+ CONFIG.parse()
+ return CONFIG
diff --git a/base/core.py b/base/core.py
index 6e42ebd..b60d9c3 100644
--- a/base/core.py
+++ b/base/core.py
@@ -34,7 +34,7 @@ PROBLEM = os.getenv("PROBLEM")
LANGUAGE = os.getenv('LANGUAGE')
# Reading problem specific options from problem config
-[COUNT, CONFIG] = config.parse()
+CONFIG = config.parse()
# Initializing log
prefix = SUBID + ':' + USER + ':' + PROBLEM + ':' + LANGUAGE + ': '
@@ -54,7 +54,7 @@ elif compret: # Unspecified Compilation error
else:
# Start running
update.status ('RUN', SUBID, -1, -1);
- arr = run.main (COUNT, CONFIG)
+ arr = run.main (CONFIG)
charstat = 'CWTMRU' # [ correct, wrong, time, memory, runtime, unexpected ]
diff --git a/base/run.py b/base/run.py
index 37aec11..dd93b69 100644
--- a/base/run.py
+++ b/base/run.py
@@ -22,17 +22,10 @@ import update
SUBID = os.getenv("SUBID")
LOGGER = os.getenv("LOGGER")
JAILER = os.getenv("JAILER")
-INPUT_DIR = os.getenv("INPUT_DIR")
def run (testnum, CONFIG):
- TIMELIM = CONFIG[1]
- MEMLIM = CONFIG[2]
- INPUT_COMMAND = INPUT_DIR + '/' + CONFIG[3]
-
- if (CONFIG[0] == 'normal'):
- INPUT_COMMAND = 'cat ' + INPUT_COMMAND
-
-# print JAILER + ' ' + str (testnum) + ' ' + str(TIMELIM) + ' ' + INPUT_COMMAND
+ [TIMELIM, MEMLIM] = CONFIG.get_limits(testnum)
+ INPUT_COMMAND = CONFIG.input_command(testnum)
update.status ('RUN', SUBID, -1, testnum)
@@ -54,30 +47,28 @@ def run (testnum, CONFIG):
mem = int (result[2])
ret = int (result[3])
- if ret > 127: status = 6 + retstat - 128 # signal
- elif ret > 124: status = 5 # unexpected
- elif ret == 124: status = 2 # time
- elif ret != 0: status = 4 # runtime
- elif mem > MEMLIM: status = 3 # memory
- elif time > TIMELIM: status = 2 # time
- elif score <= 0: status = 1 # wrong
- else: status = 0 # correct
+ if ret > 127: status = 6 + ret - 128 # signal
+ elif ret > 124: status = 5 # unexpected
+ elif ret == 124: status = 2 # time
+ elif ret != 0: status = 4 # runtime
+ elif mem > MEMLIM: status = 3 # memory
+ elif time > TIMELIM: status = 2 # time
+ elif score <= 0: status = 1 # wrong
+ else: status = 0 # correct
os.system(LOGGER + " LOG error {0} {1} {2} {3} {4} {5} {6}".format(SUBID, status, testnum, time, mem, ret, score))
- error = update.status ('RUN', SUBID, status, testnum, time, mem, score)
+ error = update.status ('RUN', SUBID, status, testnum)
return [status, error]
-#strstat = [ 'Accepted!', 'Wrong answer', 'Time limit exceeded', 'Memory limit exceeded', 'Run time error', 'Unexpected error', 'Signal #' ]
-
-def main(COUNT, CONFIG):
+def main(CONFIG):
arr = []
- for i in range(COUNT):
- [status, error] = run (i, CONFIG[i])
+ for i in range(CONFIG.count):
+ [status, error] = run (i, CONFIG)
arr.append(status)
if error:
- break
+ break;
update.status ('END', SUBID, status)