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

Segfault in program "Name" when input is p1 as affine cryst group on right #112

Open
kiryph opened this issue Aug 30, 2023 · 1 comment
Open

Comments

@kiryph
Copy link

kiryph commented Aug 30, 2023

❯ cat ~/p1-group-right
#2
3
1 0 0
0 1 0
1 0 1
3
1 0 0
0 1 0
0 1 1

❯ ./bin/Name ~/p1-group-right
[1]    46017 segmentation fault  ./bin/Name ~/p1-group-right

p1 given as as space group on left still does not work. However, the program does not segfault but returns the error error in coboundary:

❯ cat ~/p1-group-left
#2
3
1 0 1
0 1 0
0 0 1
3
1 0 0
0 1 1
0 0 1

❯ ./bin/Name ~/p1-group-left
error in coboundary

The program works fine for p2, ... and other plane groups:

❯ cat ~/p2-group-right
#3
3
-1 0 0
0 -1 0
0 0 1
3
1 0 0
0 1 0
1 0 1
3
1 0 0
0 1 0
0 1 1

❯ ./bin/Name ~/p2-group-right
qname: group.1 zname: 1 1 aff_name: 0

Carat Version

Carat is compiled from github with latest commits:

❯ git log -n 2
commit 21bfdb516cc21c8e634a9fc99c469a07b8c7490c (HEAD -> master, origin/master, origin/HEAD)
Author: Jerry James <[email protected]>
Date:   Mon Aug 15 13:18:53 2022 -0600

    Avoid a use after free

commit fd0b757974c491203e050912c09ac0bd504c7700
Author: Max Horn <[email protected]>
Date:   Sun Oct 17 21:00:09 2021 +0200

    Improve setup_carat_location on macOS

    The macro SYS_IS_DARWIN is only valid in GAP, so this code was never used before

Backtrace with lldb

❯ lldb ./bin/Name ~/p1-group-right
(lldb) target create "./bin/Name"
Current executable set to '/Users/kiryph/.local/stow/carat/bin/Name' (x86_64).
(lldb) settings set -- target.run-args  "/Users/kiryph/p1-group-right"
(lldb) r
Process 47344 launched: '/Users/kiryph/.local/stow/carat/bin/Name' (x86_64)
Process 47344 stopped
* thread #1, queue = 'com.apple.main-thread', stop reason = EXC_BAD_ACCESS (code=1, address=0x4)
    frame #0: 0x00000001002cedb5 libgmp.10.dylib`__gmpz_mul + 34
libgmp.10.dylib`:
->  0x1002cedb5 <+34>: movslq 0x4(%rsi), %rax
    0x1002cedb9 <+38>: movq   %rax, %rcx
    0x1002cedbc <+41>: negq   %rcx
    0x1002cedbf <+44>: cmovlq %rax, %rcx
Target 0: (Name) stopped.
(lldb) bt
* thread #1, queue = 'com.apple.main-thread', stop reason = EXC_BAD_ACCESS (code=1, address=0x4)
  * frame #0: 0x00000001002cedb5 libgmp.10.dylib`__gmpz_mul + 34
    frame #1: 0x0000000100035b19 Name`MP_solve_mat(M=0x0000600000004fa0, rows=<unavailable>, cols=<unavailable>, B=0x0000600000004a30, Bcols=<unavailable>, X1cols=0x00007ff7bfefd774, X0kgv=0x00007ff7bfefd730) at MP_solve.c:170:11 [opt]
    frame #2: 0x0000000100030d6e Name`long_solve_mat(A=0x0000600000c00d20, B=0x0000600000c00180) at long_solve_mat.c:47:8 [opt]
    frame #3: 0x000000010005b665 Name`coboundary(G=0x0000000100405180, C=0x0000600000c00180, T=0x0000600000c002d0) at coboundary.c:84:9 [opt]
    frame #4: 0x00000001000441cb Name`aff_class_inf(R=<unavailable>, DATAZ=0x0000000100405180, PRES=0x0000600000c003c0, aff_name=0x00007ff7bfefe8d8, RC=0x0000000000000000) at aff_class_inf.c:183:7 [opt]
    frame #5: 0x0000000100002fca Name`main(argc=<unavailable>, argv=<unavailable>) at name.c:0:9 [opt]
    frame #6: 0x000000010009552e dyld`start + 462
(lldb)
@kiryph
Copy link
Author

kiryph commented Aug 31, 2023

Additional Debugging

Since the source code of CARAT contains debug output when setting INFO_LEVEL via the command line option -h, I observed a different code path with -h=4.

In order to allow -h=4, the source code for src/name.c must be modified:

diff --git a/src/name.c b/src/name.c
index 193d3e1..8d4873e 100644
--- a/src/name.c
+++ b/src/name.c
@@ -48,7 +48,7 @@ int main (int argc, char *argv[])
   if (is_option('h'))
     INFO_LEVEL = optionnumber('h');

-  if ((is_option('h') && INFO_LEVEL != 8) || FILEANZ == 0)
+  if ((is_option('h') && INFO_LEVEL == 0) || FILEANZ == 0)
     {
       printf("Usage: %s file [-T] [-Z] [-o] [-M] [-c]\n",argv[0]);
       printf("\n");

Again the program segfaults but at a different place:

lldb -- ./bin/Name ~/p1-group-right -h=4
(lldb) target create "./bin/Name"
Current executable set to '/Users/kiryph/.local/stow/carat/bin/Name' (x86_64).
(lldb) settings set -- target.run-args  "/Users/kiryph/p1-group-right" "-h=4"
(lldb) r
...
entering cong_solve
2d0	% loesungen[1]
1
2d0	% umform
1
2	% A
 1 0
 0 1
2d0	% loesungen[1]
1
2d0	% umform
1
2x0	% loesungen[0]


0	% loesungen[1]
2x0	% cozykel


0d0	% elementar
Process 79019 stopped
* thread #1, queue = 'com.apple.main-thread', stop reason = EXC_BAD_ACCESS (code=1, address=0x0)
    frame #0: 0x0000000100026dff Name`fput_mat(outfile=0x00007ff85c7e9998, mat=0x0000600000c0c1b0, comment="elementar", options=2) at put_mat.c:155:35
   152 	  if ( flags.Integral || Normalized ) {
   153 	    if ( flags.Diagonal ) {
   154 	      if ( flags.Scalar ) {
-> 155 	        fprintf (outfile, "%d\n", mat->array.SZ[0][0]);
   156 	      } else {
   157 	        for ( i  = 0 ; i < mat->rows; i++  ) {
   158 	          fprintf (outfile, "%d ", mat->array.SZ[i][i]);
Target 0: (Name) stopped.
(lldb) bt
* thread #1, queue = 'com.apple.main-thread', stop reason = EXC_BAD_ACCESS (code=1, address=0x0)
  * frame #0: 0x0000000100026dff Name`fput_mat(outfile=0x00007ff85c7e9998, mat=0x0000600000c0c1b0, comment="elementar", options=2) at put_mat.c:155:35
    frame #1: 0x0000000100026b2f Name`put_mat(mat=0x0000600000c0c1b0, file_name=0x0000000000000000, comment="elementar", options=2) at put_mat.c:74:3
    frame #2: 0x0000000100065111 Name`cohomology(dim=0x00007ff7bfefd7f8, mat=0x0000600000009260, matinv=0x000060000000c010, relator=0x000060000020c020, erzeuger=1, relatoren=1) at zass.c:400:8
    frame #3: 0x00000001000472c9 Name`aff_class_inf(R=0x00000001005046c0, DATAZ=0x0000000100504e40, PRES=0x0000600000c08360, aff_name=0x00007ff7bfefe8a8, RC=0x0000000000000000) at aff_class_inf.c:165:8
    frame #4: 0x000000010000192f Name`main(argc=3, argv=0x00007ff7bfefea60) at name.c:156:10
    frame #5: 0x00000001000a152e dyld`start + 462

Intermediate stdlog output is omitted.

This is strange. The debug level for additional output should not have an influence on the code path.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant