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 authored and fingolfin committed Sep 29, 2023
1 parent 0fb705c commit bdb4f57
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 8 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);
}
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);
18 changes: 10 additions & 8 deletions tst/testinstall/recordname.tst
Original file line number Diff line number Diff line change
Expand Up @@ -92,8 +92,9 @@ sitive integer)
gap> \.(r, "a");
Error, Record Element: <rnam> must be a positive small integer (not a list (st\
ring))
gap> \.(r, 1000000);
Error, Record Element: <rnam> must be a valid rnam (not the integer 1000000)
gap> \.(r, 1000000000);
Error, Record Element: <rnam> must be a valid rnam (not the integer 1000000000\
)
##
gap> IsBound\.(r, RNamObj("y"));
Expand All @@ -112,8 +113,9 @@ sitive integer)
gap> IsBound\.(r, "a");
Error, Record IsBound: <rnam> must be a positive small integer (not a list (st\
ring))
gap> IsBound\.(r, 1000000);
Error, Record IsBound: <rnam> must be a valid rnam (not the integer 1000000)
gap> IsBound\.(r, 1000000000);
Error, Record IsBound: <rnam> must be a valid rnam (not the integer 1000000000\
)
##
gap> r;
Expand All @@ -137,8 +139,8 @@ itive integer)
gap> Unbind\.(r, "a");
Error, Record Unbind: <rnam> must be a positive small integer (not a list (str\
ing))
gap> Unbind\.(r, 1000000);
Error, Record Unbind: <rnam> must be a valid rnam (not the integer 1000000)
gap> Unbind\.(r, 1000000000);
Error, Record Unbind: <rnam> must be a valid rnam (not the integer 1000000000)
##
gap> r;
Expand All @@ -164,7 +166,7 @@ Error, Record Assignment: <rnam> must be a positive small integer (not a large\
gap> \.\:\=(r, "a", 1);
Error, Record Assignment: <rnam> must be a positive small integer (not a list \
(string))
gap> \.\:\=(r, 1000000, 1);
gap> \.\:\=(r, 1000000000, 1);
Error, Record Assignment: <rnam> must be a valid rnam (not the integer 1000000\
)
000)
gap> STOP_TEST( "recordname.tst", 1);

0 comments on commit bdb4f57

Please sign in to comment.