Skip to content

Commit

Permalink
Catch overflow in header size
Browse files Browse the repository at this point in the history
  • Loading branch information
ChrisJefferson committed Sep 25, 2023
1 parent 0fb705c commit 412efb9
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 0 deletions.
4 changes: 4 additions & 0 deletions src/code.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Check warning on line 264 in src/code.c

View check run for this annotation

Codecov / codecov/patch

src/code.c#L264

Added line #L264 was not covered by tests
}
header->type = type;
RegisterStatWithHook(GET_GAPNAMEID_BODY(cs->currBody), line, type);
// return the new statement
Expand Down
24 changes: 24 additions & 0 deletions tst/testinstall/function.tst
Original file line number Diff line number Diff line change
Expand Up @@ -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);

0 comments on commit 412efb9

Please sign in to comment.