diff --git a/src/code.c b/src/code.c index 8e8ddb6794f..1b5a237fe77 100644 --- a/src/code.c +++ b/src/code.c @@ -259,6 +259,10 @@ Stat NewStatOrExpr(CodeState * cs, UInt type, UInt size, UInt line) StatHeader * header = STAT_HEADER(cs, stat); header->line = line; header->size = size; + // check size fits inside header + if (header->size != size) { + ErrorQuit("function too large for parser", 0, 0); + } header->type = type; RegisterStatWithHook(GET_GAPNAMEID_BODY(cs->currBody), line, type); // return the new statement diff --git a/tst/testinstall/function.tst b/tst/testinstall/function.tst index 039f57dd6eb..99ec0ce7e0e 100644 --- a/tst/testinstall/function.tst +++ b/tst/testinstall/function.tst @@ -339,5 +339,29 @@ function ( x ) return ([ [ x ] ]{[ 1 ]}{[ 1 ]})[1, 1]; end gap> funcloop(x -> ([ [ x ] ]{[ 1 ]}{[ 1 ]}){[ 1 ]}); # EXPR_ELMS_LIST function ( x ) return ([ [ x ] ]{[ 1 ]}{[ 1 ]}){[ 1 ]}; end +# Test functions with very large lists +gap> funcstr := String(List([1..2097151], x -> x));; +gap> funcstr := Concatenation("func := function() return ", funcstr, "; end;");; +gap> Read(InputTextString(funcstr));; +gap> func() = [1..2097151]; +true +gap> funcstr := String(List([1..2097152], x -> x));; +gap> funcstr := Concatenation("func := function() return ", funcstr, "; end;");; +gap> Read(InputTextString(funcstr));; +Error, function too large for parser + +# Test functions with very large records +gap> r := rec();; for x in [1..2097150/2] do r.(x) := x; od;; +gap> funcstr := String(r);; +gap> funcstr := Concatenation("func := function() return ", funcstr, "; end;");; +gap> Read(InputTextString(funcstr));; +gap> func() = r; +true +gap> r := rec();; for x in [1..2097152/2] do r.(x) := x; od;; +gap> funcstr := String(r);; +gap> funcstr := Concatenation("func := function() return ", funcstr, "; end;");; +gap> Read(InputTextString(funcstr));; +Error, function too large for parser + # gap> STOP_TEST("function.tst", 1);