From 64833a04085b33948256caa4d6a787a9f15d08db Mon Sep 17 00:00:00 2001 From: Brikaa Date: Fri, 15 Oct 2021 14:25:33 +0200 Subject: [PATCH 1/4] pkg(file-0.0.1): Run executable --- api/src/api/v2.js | 19 ++++++++++--------- api/src/job.js | 8 ++++++-- packages/file/0.0.1/build.sh | 3 +++ packages/file/0.0.1/environment | 3 +++ packages/file/0.0.1/metadata.json | 5 +++++ packages/file/0.0.1/run | 6 ++++++ packages/file/0.0.1/test.file | Bin 0 -> 16568 bytes readme.md | 1 + 8 files changed, 34 insertions(+), 11 deletions(-) create mode 100755 packages/file/0.0.1/build.sh create mode 100644 packages/file/0.0.1/environment create mode 100644 packages/file/0.0.1/metadata.json create mode 100644 packages/file/0.0.1/run create mode 100755 packages/file/0.0.1/test.file diff --git a/api/src/api/v2.js b/api/src/api/v2.js index c0526f4..d6cd3f2 100644 --- a/api/src/api/v2.js +++ b/api/src/api/v2.js @@ -87,15 +87,6 @@ function get_job(body) { } } - if ( - files.filter(file => !file.encoding || file.encoding === 'utf8') - .length === 0 - ) { - return reject({ - message: 'files must include at least one utf8 encoded file', - }); - } - const rt = runtime.get_latest_runtime_matching_language_version( language, version @@ -106,6 +97,16 @@ function get_job(body) { }); } + if ( + rt.language !== 'file' && + files.filter(file => !file.encoding || file.encoding === 'utf8') + .length === 0 + ) { + return reject({ + message: 'files must include at least one utf8 encoded file', + }); + } + for (const constraint of ['memory_limit', 'timeout']) { for (const type of ['compile', 'run']) { const constraint_name = `${type}_${constraint}`; diff --git a/api/src/job.js b/api/src/job.js index 7acff22..ca95e6f 100644 --- a/api/src/job.js +++ b/api/src/job.js @@ -222,7 +222,9 @@ class Job { } runtime=${this.runtime.toString()}` ); - const code_files = this.files.filter(file => file.encoding == 'utf8'); + const code_files = + (this.runtime.language === 'file' && this.files) || + this.files.filter(file => file.encoding == 'utf8'); logger.debug('Compiling'); @@ -270,7 +272,9 @@ class Job { } gid=${this.gid} runtime=${this.runtime.toString()}` ); - const code_files = this.files.filter(file => file.encoding == 'utf8'); + const code_files = + (this.runtime.language === 'file' && this.files) || + this.files.filter(file => file.encoding == 'utf8'); if (this.runtime.compiled) { eventBus.emit('stage', 'compile'); diff --git a/packages/file/0.0.1/build.sh b/packages/file/0.0.1/build.sh new file mode 100755 index 0000000..d7ab47e --- /dev/null +++ b/packages/file/0.0.1/build.sh @@ -0,0 +1,3 @@ +#!/bin/bash + +# Nothing to do here diff --git a/packages/file/0.0.1/environment b/packages/file/0.0.1/environment new file mode 100644 index 0000000..d5a7803 --- /dev/null +++ b/packages/file/0.0.1/environment @@ -0,0 +1,3 @@ +#!/bin/bash + +export PATH=$PWD:$PATH diff --git a/packages/file/0.0.1/metadata.json b/packages/file/0.0.1/metadata.json new file mode 100644 index 0000000..ae34ae9 --- /dev/null +++ b/packages/file/0.0.1/metadata.json @@ -0,0 +1,5 @@ +{ + "language": "file", + "version": "0.0.1", + "aliases": ["executable", "elf", "binary"] +} diff --git a/packages/file/0.0.1/run b/packages/file/0.0.1/run new file mode 100644 index 0000000..77ed0a6 --- /dev/null +++ b/packages/file/0.0.1/run @@ -0,0 +1,6 @@ +#!/bin/bash + +filename="$1" +chmod +x "$filename" +shift +./"$filename" "$@" diff --git a/packages/file/0.0.1/test.file b/packages/file/0.0.1/test.file new file mode 100755 index 0000000000000000000000000000000000000000..8c7a67d92841fc71dd40ef76305328833c4aab6e GIT binary patch literal 16568 zcmeHOZ*Wvs6~DV75Ck?0ZAwa&td-6{F-rmgL!H>&Bpcq^04Yf zZKzVI(VCS;(GN<;en`hZ)v2R6`hkAXmO*NrsScfSYVDs99b1D_D@AcqEv&zD?>(Eh zkEGLf`pJ2B=Iy!Xch2wJ`_8-X<=wn{KNsum@%wy&OO5!LAZ;qBkcc+SwCf5)M6`=# z_-zua#X{%{B&O^UC16$MIe)dR(|8Re@fxWzhkU<+1xxNBN#e~{rWPp+OQFw$c(r8G zx?6r%_md^tEA54dj1rQ+75RN~Kw;_RQEn!hrCCgLxTJ3Hv_6045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a_0V#+)!e~Oxd}7 z!Aum#L^78d9kFaH6>gc^!^FD#w3*1~69-HyYv&J$efdPjGE>D&<^U)T&4j02}@7WRE9`Ay!s?(`zKyI6;w6L?Mr$07e4n#Y9V~A>{5_ST+CU&B;sdUyX7A&IE z#s%K15OHogzy&De%we1ZZMJZ1aH#frcY7*S487ICG_kRRPag5)o(h)-bzbeEKwpLm z1+LG%HN!=g8!(cEqD`1BVrU(}fWbDKc zq@7oCm}}`QcE5~@a5iUK;r-cScr>3Iwet1>2Q*YnWB*e+rJ-nNyqWGZ={}q&42y8; zKo(6XY3G&YE-PQa(5zBS*z(p$f(W`cI%12k9PeRN!~1hksZy|#B8+V>P-VWt`J5bP zVQX05YQrf+V@<_S_ncyI9Ze-NX#`VrTwxK$&7Q$MJjZkFokH{;jYls2Mylf8$H?!| z+AMv!PVz%I=-rk1^X=CoUn=~*sx%?CpyK4a_wB7=M=km9BE$4v{nk%r*^97a>&F36*|1~ToQK2p~pXVUN4AegJ>zJqI0Bp|UZlC5GPX3)C<;~I{qocU{^D=B$ zrY!G4a^v@V-e>F17xP)Z4ob2x?H!f-78k+Uspj?g~K@|j~%CLyAF6r510?YNOMl^KR Date: Fri, 15 Oct 2021 16:51:11 +0200 Subject: [PATCH 2/4] Check for base64 in CLI --- cli/commands/execute.js | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/cli/commands/execute.js b/cli/commands/execute.js index c69d3a0..4929ccc 100644 --- a/cli/commands/execute.js +++ b/cli/commands/execute.js @@ -245,9 +245,18 @@ async function run_non_interactively(files, argv) { exports.handler = async argv => { const files = [...(argv.files || []), argv.file].map(file_path => { + const encoding = + (fs + .readFileSync(file_path) + .toString() + .split('') + .some(x => x.charCodeAt(0) >= 128) && + 'base64') || + 'utf8'; return { name: path.basename(file_path), - content: fs.readFileSync(file_path).toString(), + content: fs.readFileSync(file_path).toString(encoding), + encoding, }; }); From 19252467cbd91920eb897cd6439f186b72b0df68 Mon Sep 17 00:00:00 2001 From: Brikaa Date: Fri, 15 Oct 2021 16:57:11 +0200 Subject: [PATCH 3/4] Use some() instead of filter() in v2.js --- api/src/api/v2.js | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/api/src/api/v2.js b/api/src/api/v2.js index d6cd3f2..4f0c3e2 100644 --- a/api/src/api/v2.js +++ b/api/src/api/v2.js @@ -99,8 +99,7 @@ function get_job(body) { if ( rt.language !== 'file' && - files.filter(file => !file.encoding || file.encoding === 'utf8') - .length === 0 + !files.some(file => !file.encoding || file.encoding === 'utf8') ) { return reject({ message: 'files must include at least one utf8 encoded file', From 52fb900603070f12c6c5b0bd7ab197aaecb897fa Mon Sep 17 00:00:00 2001 From: Brikaa Date: Sat, 16 Oct 2021 11:55:22 +0200 Subject: [PATCH 4/4] Don't read the file twice --- cli/commands/execute.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/cli/commands/execute.js b/cli/commands/execute.js index 4929ccc..0d906bc 100644 --- a/cli/commands/execute.js +++ b/cli/commands/execute.js @@ -245,9 +245,9 @@ async function run_non_interactively(files, argv) { exports.handler = async argv => { const files = [...(argv.files || []), argv.file].map(file_path => { + const buffer = fs.readFileSync(file_path); const encoding = - (fs - .readFileSync(file_path) + (buffer .toString() .split('') .some(x => x.charCodeAt(0) >= 128) && @@ -255,7 +255,7 @@ exports.handler = async argv => { 'utf8'; return { name: path.basename(file_path), - content: fs.readFileSync(file_path).toString(encoding), + content: buffer.toString(encoding), encoding, }; });