diff options
-rw-r--r-- | src/program.c | 12 |
1 files changed, 12 insertions, 0 deletions
diff --git a/src/program.c b/src/program.c index 8a17ac9..55bfda4 100644 --- a/src/program.c +++ b/src/program.c @@ -8,6 +8,9 @@ #include <errno.h> #include <assert.h> +/* One gigabyte */ +#define PROGRAM_MAX_SIZE 1024*1024*1024 + /* TODO: If system is big-endian, then do endian conversion for all reads */ /* This matches SsaNumberType */ @@ -136,6 +139,11 @@ static CHECK_RESULT int amal_program_set_exported_function_instruction_offset_ad } int amal_program_append_bytecode(amal_program *self, Bytecode *bytecode) { + /* Sanity check for indices used later. A program shouldn't be more than 1gb */ + if(self->data.size + bytecode->data.size > PROGRAM_MAX_SIZE) { + amal_log_error("Program is too large. Max size is 1GB"); + return -1; + } return buffer_append(&self->data, bytecode->data.data, bytecode->data.size); } @@ -567,6 +575,10 @@ static CHECK_RESULT int amal_program_read_instructions(amal_program *self, amal_ int amal_program_run(amal_program *self) { int result; amal_executor *executor; + if(self->data.size > PROGRAM_MAX_SIZE) { + amal_log_error("Program is too large. Max size is 1GB"); + return AMAL_PROGRAM_ERR; + } result = AMAL_PROGRAM_ERR; return_if_error(amal_executor_init(&executor)); |