Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Reject GAP function definitions containing huge list or record expressions (millions of entries) instead of silently discarding part of the data #5509

Merged
merged 1 commit into from
Oct 11, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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) {
fingolfin marked this conversation as resolved.
Show resolved Hide resolved
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
25 changes: 25 additions & 0 deletions tst/testinstall/function.tst
Original file line number Diff line number Diff line change
Expand Up @@ -339,5 +339,30 @@ 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> r := List([1..(16777216/GAPInfo.BytesPerVariable)-1]);;
gap> funcstr := String(r);;
gap> funcstr := Concatenation("func := function() return ", funcstr, "; end;");;
gap> Read(InputTextString(funcstr));;
gap> func() = r;
true
gap> funcstr := String(List([1..(16777216/GAPInfo.BytesPerVariable)], 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..(16777216/GAPInfo.BytesPerVariable-2)/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..(16777216/GAPInfo.BytesPerVariable)/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);
16 changes: 8 additions & 8 deletions tst/testinstall/recordname.tst
Original file line number Diff line number Diff line change
Expand Up @@ -92,8 +92,8 @@ 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, 100000000);
Error, Record Element: <rnam> must be a valid rnam (not the integer 100000000)

##
gap> IsBound\.(r, RNamObj("y"));
Expand All @@ -112,8 +112,8 @@ 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, 100000000);
Error, Record IsBound: <rnam> must be a valid rnam (not the integer 100000000)

##
gap> r;
Expand All @@ -137,8 +137,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, 100000000);
Error, Record Unbind: <rnam> must be a valid rnam (not the integer 100000000)

##
gap> r;
Expand All @@ -164,7 +164,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, 100000000, 1);
Error, Record Assignment: <rnam> must be a valid rnam (not the integer 1000000\
)
00)
gap> STOP_TEST( "recordname.tst", 1);