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

Crash when ApplicableMethod is called incorrectly #3116

Closed
ssiccha opened this issue Dec 18, 2018 · 5 comments · Fixed by #3151
Closed

Crash when ApplicableMethod is called incorrectly #3116

ssiccha opened this issue Dec 18, 2018 · 5 comments · Fixed by #3151
Labels
kind: bug: crash Issues describing bugs that cause GAP to crash, and PRs fixing them (used for release notes) kind: bug Issues describing general bugs, and PRs fixing them

Comments

@ssiccha
Copy link
Contributor

ssiccha commented Dec 18, 2018

On current master 5dad0ef:

gap> obj := RandomMat(20, 20, GF(5));; 
gap> ConvertToMatrixRep(obj);
5
gap> ApplicableMethod(PostMakeImmutable, [obj]); #this works as expected
function( m ) ... end
gap> ApplicableMethod(PostMakeImmutable, obj); #this crashes
Segmentation fault
@ssiccha ssiccha added kind: bug: crash Issues describing bugs that cause GAP to crash, and PRs fixing them (used for release notes) topic: library and removed topic: library labels Dec 18, 2018
@fingolfin
Copy link
Member

Simpler way to reproduce it (and running in a GAP debug build with assertions enabled):

gap> ApplicableMethod(PostMakeImmutable, [1..10]);
Assertion failed: (0 <= i && i < 8), function METHS_OPER, file ../../src/opers.h, line 180.
Abort trap: 6

So clearly a bounds check is missing somewhre

@cdwensley
Copy link
Contributor

The second parameter for ApplicableMethod should be a list of parameters for the operation, so the first call is correct, and the second is only accepted for the convenience of users. When 'obj' is used instead of '[obj]' it happens that obj is a list (of 20 mutable compressed vectors of length 20 over GF(5)). The segmentation fault occurs when

methods:=MethodsOperation(oper,narg);

is called with narg=20. Please remind me: what is the maximum number of parameters for an operation?

@cdwensley
Copy link
Contributor

Using 18 in place of 20 we get:

gap> obj := RandomMat(18,18, GF(5));;
gap> ConvertToMatrixRep(obj);
5
gap> ApplicableMethod(PostMakeImmutable, obj);
Error, Range: <last>-<first> (-7) must be divisible by <inc> (24) in
  LENGTH( meths ) at /Applications/gap/gapdev/lib/oper.g:1918 called from 
MethodsOperation( oper, narg ) at lib/methwhy.g:266 called from
CallFuncList( ApplicableMethodTypes, arg ) at lib/methwhy.g:438 called from
<function "ApplicableMethod">( <arguments> )
 called from read-eval loop at *stdin*:6
type 'quit;' to quit to outer loop

in the loop (oper.g line 1918) where len=24 and LENGTH(meths)=17:

    for i in [0, len .. LENGTH(meths) - len] do

@cdwensley
Copy link
Contributor

Revised Pull Request #2948 to add a test in ApplicableMethod to check that the number of entries in the second parameter is not greater than 8. Also added a test in tst/testinstall/methwhy.tst.

@fingolfin
Copy link
Member

I fixed the underlying problem in PR #3151. It should not be necessary to add another check to ApplicableMethod, but of course it won't hurt either.

@fingolfin fingolfin added the kind: bug Issues describing general bugs, and PRs fixing them label Mar 21, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
kind: bug: crash Issues describing bugs that cause GAP to crash, and PRs fixing them (used for release notes) kind: bug Issues describing general bugs, and PRs fixing them
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants