Runtime error with UBSAN
Second problem reported here, https://www.stats.ox.ac.uk/pub/bdr/memtests/gcc-UBSAN/rswipl/rswipl-Ex.Rout The problem is shown if the compiler switch -fsanitize=address,undefined is used.
/data/gannet/ripley/R/packages/tests-gcc-SAN/rswipl/src/swipl-devel/src/os/pl-buffer.c:184:5: runtime error: shift exponent 734 is too large for 32-bit type 'int'
One can suppress the error message by limiting the number of shifts in a >> b to the width of a [something like “b < 32 ? a >> b : 0”, or use a mask such as a >> (b & 0x1f), but the error indicates that there may be some problem in the code that invokes the bit shift.
I pushed fixes for the two shift issues. Both seem innocent on current hardware and software, but fixing was cheap. I don't understand the alignment error.
Unfortunately, the error with the shift exponent is still there. I don't really understand what is going on, but superficially, line 183 of pl-buffer seems still a bit strange:
size_t discard = i<16 ? 0 : BUFFER_DISCARD_ABOVE>>i; /* discard higher buffers earlier */
For small i, discard is zero. For large i, discard is also zero, since BUFFER_DISCARD_ABOVE [i.e., 4096] >> i is also zero (?).
To reproduce the UBSAN messages, I changed -fsanitize=address to -fsanitize=address,undefined in line 58 of swipl-devel/cmake/BuildType.cmake
i<16
Oops. The value doesn't really matter, it just defines some policy in reclaiming memory and (thus) any value is fine. Pushed da8bc95cea5500267e1a4b2050a94ba2aa7a072e.
I'll have a look (but not now).
I don't understand the alignment error.
In pl-index.c, line around 2240, we have:
static int
assess_remove_duplicates(hash_assessment *a, size_t clause_count)
{ key_asm *s = a->keys;
key_asm *o = a->keys-1; /* I think this may cause a problem since a->keys may be NULL (?) */
key_asm *e = &s[a->size];
word c = 0; /* invalid key */
size_t fc = 0;
size_t i = 0;
float A=0.0, Q=0.0;
a->speedup = 0.0;
if ( !a->keys ) /* see here */
return FALSE;
I guess key_asm *o = a->keys-1; can safely be moved below, after the check if a->keys is non-NULL.
pushed 1a795a4b77f49b5b408adcd66c195275325e47da to delay declarations to after checking for the keys. Quite likely optimizing avoids this as well :smile:
With the latest commit (321ea1cae0ccef17dee00fc1b2efc5f1902cdf28), I get quite a few errors from g++ 12.2.0 and -fsanitize=address,undefined like this:
/home/peter/src/swipl-devel/src/pl-qlf.c:587:13: runtime error: left shift of negative value -1
/home/peter/src/swipl-devel/src/pl-comp.c:1960:15: runtime error: member access within misaligned address 0x000000000006 for type 'struct functor', which requires 8 byte alignment
0x000000000006: note: pointer points here
<memory cannot be printed>
/home/peter/src/swipl-devel/src/pl-comp.c:1960:15: runtime error: member access within misaligned address 0x000000000ee2 for type 'struct functor', which requires 8 byte alignment
0x000000000ee2: note: pointer points here
<memory cannot be printed>
/home/peter/src/swipl-devel/src/pl-thread.c:7648:3: runtime error: null pointer passed as argument 1, which is declared to never be null
/home/peter/src/swipl-devel/src/pl-thread.c:7648:3: runtime error: null pointer passed as argument 2, which is declared to never be null
[2302/2633] Build home/library/lynx/INDEX.pl
/home/peter/src/swipl-devel/src/pl-comp.c:1960:15: runtime error: member access within misaligned address 0x000000000ee2 for type 'struct functor', which requires 8 byte alignment
0x000000000ee2: note: pointer points here
<memory cannot be printed>
/home/peter/src/swipl-devel/src/pl-thread.c:7648:3: runtime error: null pointer passed as argument 1, which is declared to never be null
/home/peter/src/swipl-devel/src/pl-thread.c:7648:3: runtime error: null pointer passed as argument 2, which is declared to never be null
Yes, indeed, but please verify: the errors are unrelated to the particular commit 321ea1c, or are they?
I don't know if the errors are related or unrelated to commit 321ea1cae0ccef17dee00fc1b2efc5f1902cdf28 -- I've never tried -fsanitize=address,undefined before.
I sync-ed to commit da8bc95cea5500267e1a4b2050a94ba2aa7a072e and got some similar error messages, such as:
[284/606] Generating ../home/boot.prc
/home/peter/src/swipl-devel/src/pl-qlf.c:587:13: runtime error: left shift of negative value -1
/home/peter/src/swipl-devel/src/pl-comp.c:1960:15: runtime error: member access within misaligned address 0x000000000006 for type 'struct functor', which requires 8 byte alignment
0x000000000006: note: pointer points here
<memory cannot be printed>
/home/peter/src/swipl-devel/src/pl-index.c:2241:12: runtime error: applying non-zero offset 18446744073709551600 to null pointer
[285/606] Building C object packages/tipc/CMakeFiles/plugin_tipc.dir/__/clib/nonblockio.c.o
[286/606] Building C object packages/tipc/CMakeFiles/plugin_tipc.dir/tipc.c.o
[287/606] Building C object packages/semweb/CMakeFiles/plugin_rdf_db.dir/rdf_db.c.o
[288/606] Building C object packages/ssl/CMakeFiles/plugin_ssl4pl.dir/ssl4pl.c.o
[289/606] Build home/library/clp/INDEX.pl
/home/peter/src/swipl-devel/src/pl-index.c:2241:12: runtime error: applying non-zero offset 18446744073709551600 to null pointer
/home/peter/src/swipl-devel/src/pl-comp.c:1960:15: runtime error: member access within misaligned address 0x000000000ee2 for type 'struct functor', which requires 8 byte alignment
0x000000000ee2: note: pointer points here
<memory cannot be printed>
[290/606] Building C object packages/jpl/CMakeFiles/plugin_libjpl.dir/src/main/c/jpl.c.o
[291/606] Build home/library/unicode/INDEX.pl
/home/peter/src/swipl-devel/src/pl-index.c:2241:12: runtime error: applying non-zero offset 18446744073709551600 to null pointer
/home/peter/src/swipl-devel/src/pl-comp.c:1960:15: runtime error: member access within misaligned address 0x000000000ee2 for type 'struct functor', which requires 8 byte alignment
0x000000000ee2: note: pointer points here
<memory cannot be printed>
[292/606] Build home/library/lynx/INDEX.pl
/home/peter/src/swipl-devel/src/pl-index.c:2241:12: runtime error: applying non-zero offset 18446744073709551600 to null pointer
/home/peter/src/swipl-devel/src/pl-comp.c:1960:15: runtime error: member access within misaligned address 0x000000000ee2 for type 'struct functor', which requires 8 byte alignment
0x000000000ee2: note: pointer points here
<memory cannot be printed>
[293/606] Build home/library/dcg/INDEX.pl
/home/peter/src/swipl-devel/src/pl-index.c:2241:12: runtime error: applying non-zero offset 18446744073709551600 to null pointer
/home/peter/src/swipl-devel/src/pl-comp.c:1960:15: runtime error: member access within misaligned address 0x000000000ee2 for type 'struct functor', which requires 8 byte alignment
0x000000000ee2: note: pointer points here
<memory cannot be printed>
[294/606] Building C object packages/ssl/CMakeFiles/plugin_crypto4pl.dir/crypt_blowfish.c.o
[295/606] Build home/library/ext/clib/INDEX.pl
/home/peter/src/swipl-devel/src/pl-index.c:2241:12: runtime error: applying non-zero offset 18446744073709551600 to null pointer
/home/peter/src/swipl-devel/src/pl-comp.c:1960:15: runtime error: member access within misaligned address 0x000000000ee2 for type 'struct functor', which requires 8 byte alignment
0x000000000ee2: note: pointer points here
<memory cannot be printed>
[296/606] Build home/library/ext/http/http/INDEX.pl
/home/peter/src/swipl-devel/src/pl-index.c:2241:12: runtime error: applying non-zero offset 18446744073709551600 to null pointer
/home/peter/src/swipl-devel/src/pl-comp.c:1960:15: runtime error: member access within misaligned address 0x000000000ee2 for type 'struct functor', which requires 8 byte alignment
0x000000000ee2: note: pointer points here
<memory cannot be printed>
[297/606] Build home/library/ext/paxos/INDEX.pl
/home/peter/src/swipl-devel/src/pl-index.c:2241:12: runtime error: applying non-zero offset 18446744073709551600 to null pointer
/home/peter/src/swipl-devel/src/pl-comp.c:1960:15: runtime error: member access within misaligned address 0x000000000ee2 for type 'struct functor', which requires 8 byte alignment
0x000000000ee2: note: pointer points here
<memory cannot be printed>
[298/606] Build home/library/ext/nlp/INDEX.pl
/home/peter/src/swipl-devel/src/pl-index.c:2241:12: runtime error: applying non-zero offset 18446744073709551600 to null pointer
/home/peter/src/swipl-devel/src/pl-comp.c:1960:15: runtime error: member access within misaligned address 0x000000000ee2 for type 'struct functor', which requires 8 byte alignment
0x000000000ee2: note: pointer points here
<memory cannot be printed>
[299/606] Build home/library/ext/mqi/INDEX.pl
/home/peter/src/swipl-devel/src/pl-index.c:2241:12: runtime error: applying non-zero offset 18446744073709551600 to null pointer
/home/peter/src/swipl-devel/src/pl-comp.c:1960:15: runtime error: member access within misaligned address 0x000000000ee2 for type 'struct functor', which requires 8 byte alignment
0x000000000ee2: note: pointer points here
<memory cannot be printed>
/home/peter/src/swipl-devel/src/pl-thread.c:7648:3: runtime error: null pointer passed as argument 1, which is declared to never be null
/home/peter/src/swipl-devel/src/pl-thread.c:7648:3: runtime error: null pointer passed as argument 2, which is declared to never be null
[300/606] Build home/library/ext/stomp/INDEX.pl
/home/peter/src/swipl-devel/src/pl-index.c:2241:12: runtime error: applying non-zero offset 18446744073709551600 to null pointer
/home/peter/src/swipl-devel/src/pl-comp.c:1960:15: runtime error: member access within misaligned address 0x000000000ee2 for type 'struct functor', which requires 8 byte alignment
0x000000000ee2: note: pointer points here
<memory cannot be printed>
[301/606] Build home/library/ext/pengines/INDEX.pl
/home/peter/src/swipl-devel/src/pl-index.c:2241:12: runtime error: applying non-zero offset 18446744073709551600 to null pointer
/home/peter/src/swipl-devel/src/pl-comp.c:1960:15: runtime error: member access within misaligned address 0x000000000ee2 for type 'struct functor', which requires 8 byte alignment
0x000000000ee2: note: pointer points here
<memory cannot be printed>
[302/606] Build home/library/ext/pldoc/INDEX.pl
/home/peter/src/swipl-devel/src/pl-index.c:2241:12: runtime error: applying non-zero offset 18446744073709551600 to null pointer
/home/peter/src/swipl-devel/src/pl-comp.c:1960:15: runtime error: member access within misaligned address 0x000000000ee2 for type 'struct functor', which requires 8 byte alignment
0x000000000ee2: note: pointer points here
<memory cannot be printed>
[303/606] Build home/library/ext/PDT/INDEX.pl
/home/peter/src/swipl-devel/src/pl-index.c:2241:12: runtime error: applying non-zero offset 18446744073709551600 to null pointer
/home/peter/src/swipl-devel/src/pl-comp.c:1960:15: runtime error: member access within misaligned address 0x000000000ee2 for type 'struct functor', which requires 8 byte alignment
0x000000000ee2: note: pointer points here
<memory cannot be printed>
/home/peter/src/swipl-devel/src/pl-thread.c:7648:3: runtime error: null pointer passed as argument 1, which is declared to never be null
/home/peter/src/swipl-devel/src/pl-thread.c:7648:3: runtime error: null pointer passed as argument 2, which is declared to never be null
[304/606] Build home/library/ext/plunit/INDEX.pl
/home/peter/src/swipl-devel/src/pl-index.c:2241:12: runtime error: applying non-zero offset 18446744073709551600 to null pointer
/home/peter/src/swipl-devel/src/pl-comp.c:1960:15: runtime error: member access within misaligned address 0x000000000ee2 for type 'struct functor', which requires 8 byte alignment
0x000000000ee2: note: pointer points here
<memory cannot be printed>
[305/606] Linking C shared module packages/semweb/rdf_db.so
[306/606] Build home/library/ext/protobufs/INDEX.pl
/home/peter/src/swipl-devel/src/pl-index.c:2241:12: runtime error: applying non-zero offset 18446744073709551600 to null pointer
/home/peter/src/swipl-devel/src/pl-comp.c:1960:15: runtime error: member access within misaligned address 0x000000000ee2 for type 'struct functor', which requires 8 byte alignment
0x000000000ee2: note: pointer points here
<memory cannot be printed>
/home/peter/src/swipl-devel/src/pl-thread.c:7648:3: runtime error: null pointer passed as argument 1, which is declared to never be null
/home/peter/src/swipl-devel/src/pl-thread.c:7648:3: runtime error: null pointer passed as argument 2, which is declared to never be null
[307/606] Build home/library/ext/redis/INDEX.pl
/home/peter/src/swipl-devel/src/pl-index.c:2241:12: runtime error: applying non-zero offset 18446744073709551600 to null pointer
/home/peter/src/swipl-devel/src/pl-comp.c:1960:15: runtime error: member access within misaligned address 0x000000000ee2 for type 'struct functor', which requires 8 byte alignment
0x000000000ee2: note: pointer points here
<memory cannot be printed>
/home/peter/src/swipl-devel/src/pl-thread.c:7648:3: runtime error: null pointer passed as argument 1, which is declared to never be null
/home/peter/src/swipl-devel/src/pl-thread.c:7648:3: runtime error: null pointer passed as argument 2, which is declared to never be null
[308/606] Build home/library/ext/protobufs/protobufs/gen_pb/google/protobuf/INDEX.pl
/home/peter/src/swipl-devel/src/pl-index.c:2241:12: runtime error: applying non-zero offset 18446744073709551600 to null pointer
/home/peter/src/swipl-devel/src/pl-comp.c:1960:15: runtime error: member access within misaligned address 0x000000000ee2 for type 'struct functor', which requires 8 byte alignment
0x000000000ee2: note: pointer points here
<memory cannot be printed>
/home/peter/src/swipl-devel/src/pl-thread.c:7648:3: runtime error: null pointer passed as argument 1, which is declared to never be null
/home/peter/src/swipl-devel/src/pl-thread.c:7648:3: runtime error: null pointer passed as argument 2, which is declared to never be null
[309/606] Build home/library/ext/protobufs/protobufs/gen_pb/google/protobuf/compiler/INDEX.pl
/home/peter/src/swipl-devel/src/pl-index.c:2241:12: runtime error: applying non-zero offset 18446744073709551600 to null pointer
/home/peter/src/swipl-devel/src/pl-comp.c:1960:15: runtime error: member access within misaligned address 0x000000000ee2 for type 'struct functor', which requires 8 byte alignment
0x000000000ee2: note: pointer points here
<memory cannot be printed>
(and more ...)
I made a few PRs already to address some of the issues. If you have an idea for pl-comp.c:1960, that would be highly appreciated.
I'm not able to spend much time looking at these now -- perhaps in a week I'll have time. The message "null pointer passed as argument 1, which is declared to never be null" seems to be a situation of passing both a null pointer and a length of 0 to memcpy() - I added if ( bytes ) to line 7648 of pl-thread.c and the error message disappeared.
There's still this message:
/home/peter/src/swipl-devel/src/pl-comp.c:1960:15: runtime error: member access within misaligned address 0x000000000ee2 for type 'struct functor', which requires 8 byte alignment
0x000000000ee2: note: pointer points here
<memory cannot be printed>
I think the one from pl-comp is the last one 💪
The error is raised for predicates with arity 0. See here, pl-comp.c, line 1960:
for ( arg = argTermP(*head, 0), n = 0; n < ci->arity; n++, arg++ )
{ if ( (rc=compileArgument(arg, A_HEAD, ci)) < 0 )
goto exit_fail;
}
Probably in argTermP(*head, 0). If I condition on arities > 0, it's gone. See code below in a bit more "Turbo Pascal"-formatting.
if(ci->arity)
{
arg = argTermP(*head, 0) ;
for(n=0; n<ci->arity; n++)
{
rc = compileArgument(arg, A_HEAD, ci) ;
if(rc < 0)
goto exit_fail ;
arg++ ;
}
}
With the latest commit (b2311c0c93cf4fc50906153433978032adfc3d35), I still see a few errors (I don't have time right now to look into these. The "archive" error might be an artifact of some of my work, although I don't think so)
45: Test command: /home/peter/src/swipl-devel/build.asan/src/swipl "-p" "foreign=" "-f" "none" "--no-packs" "--on-error=status" "-s" "/home/peter/src/swipl-devel/packages/cpp/test_ffi.pl" "-g" "test_ffi" "-t" "halt"
45: Working Directory: /home/peter/src/swipl-devel/build.asan/packages/cpp
45: Test timeout computed to be: 10000000
46: % Start unit: cpp
45: % Start unit: ffi
45: % [1/62] ffi:range1 .................................................... passed (0.048 sec)
45: % [2/62] ffi:range2 ../home/peter/src/swipl-devel/src/pl-fli.c:4223:3: runtime error: left shift of negative value -1
45: .................................................. passed (0.001 sec)
45: % [3/62] ffi:range3a ................................................... passed (0.000 sec)
(This test seems to be triggered by test range2 in test_ffi.pl)
The following tests FAILED:
33 - clib:crypt (SEGFAULT)
76 - archive:archive (Failed)
81 - jpl:prolog_in_java (Failed)
70: Test command: /home/peter/src/swipl-devel/build.asan/src/swipl "-p" "foreign=:/home/peter/src/swipl-devel/build.asan/packages/sgml:/home/peter/src/swipl-devel/build.asan/packages/clib:/home/peter/src/swipl-devel/build.asan/packages/zlib:/home/peter/src/swipl-devel/build.asan/packages/http:/home/peter/src/swipl-devel/build.asan/packages/plunit:/home/peter/src/swipl-devel/build.asan/packages/RDF" "-f" "none" "--no-packs" "--on-error=status" "-s" "/home/peter/src/swipl-devel/packages/semweb/test_subprop.pl" "-g" "test_subprop" "-t" "halt"
70: Working Directory: /home/peter/src/swipl-devel/build.asan/packages/semweb
70: Test timeout computed to be: 10000000
33: % Start unit: crypt
33: % [1/16] crypt:default ..
33: ERROR: Received fatal signal 11 (segv)
33: Time: Sun May 5 11:01:39 2024
33: Inferences: 502460
33: Thread: 1 (main)
33: C-stack trace labeled "crash":
76: % Start unit: archive
33: [0] __interceptor_backtrace.part.0() at /build/gcc-12-bTRWOB/gcc-12-12.2.0/build/x86_64-linux-gnu/libsanitizer/asan/../../../../src/libsanitizer/sanitizer_common/sanitizer_common_interceptors.inc:4277 [0x7f7c7ea51f31]
33: [1] save_backtrace() at /home/peter/src/swipl-devel/src/os/pl-cstack.c:335 [0x7f7c7db43352]
33: [2] sigCrashHandler() at /home/peter/src/swipl-devel/src/os/pl-cstack.c:937 [0x7f7c7db44f18]
33: [3] dispatch_signal() at /home/peter/src/swipl-devel/src/pl-setup.c:579 (discriminator 6) [0x7f7c7d7ebafd]
76: % [1/12] archive:smoke_test_open ....................................... passed (0.439 sec)
33: [4] pl_signal_handler() at /home/peter/src/swipl-devel/src/pl-setup.c:617 [0x7f7c7d7ebfc9]
33: [5] __restore_rt() at libc_sigaction.c:? [0x7f7c7c25b050]
33: Last stack shift at 217317 inferences
33: C-stack trace labeled "SHIFT":
76: % [2/12] archive:create_and_entries .................................... passed (0.965 sec)
33: [0] __interceptor_backtrace.part.0() at /build/gcc-12-bTRWOB/gcc-12-12.2.0/build/x86_64-linux-gnu/libsanitizer/asan/../../../../src/libsanitizer/sanitizer_common/sanitizer_common_interceptors.inc:4277 [0x7f7c7ea51f31]
33: [1] save_backtrace() at /home/peter/src/swipl-devel/src/os/pl-cstack.c:335 [0x7f7c7db43352]
33: [2] growStacks() at /home/peter/src/swipl-devel/src/pl-gc.c:5634 [0x7f7c7d6d3f9e]
76: % [3/12] archive:create_and_open_named ................................. passed (0.763 sec)
33: [3] f_ensureStackSpace___LD() at /home/peter/src/swipl-devel/src/pl-gc.c:4717 [0x7f7c7d6c6833]
33: [4] ensureStackSpace_ex___LD() at /home/peter/src/swipl-devel/src/pl-gc.h:121 [0x7f7c7da3847c]
33: [5] PL_unify_list___LD() at /home/peter/src/swipl-devel/src/pl-fli.c:3354 [0x7f7c7da5355f]
33: [6] read_list___LD() at /home/peter/src/swipl-devel/src/pl-read.c:4326 [0x7f7c7d7bdbbb]
33: [7] simple_term___LD() at /home/peter/src/swipl-devel/src/pl-read.c:4744 [0x7f7c7d7c129b]
33: [8] complex_term___LD() at /home/peter/src/swipl-devel/src/pl-read.c:4186 [0x7f7c7d7bc83a]
33: [9] read_compound___LD() at /home/peter/src/swipl-devel/src/pl-read.c:4491 [0x7f7c7d7bf362]
33: [10] simple_term___LD() at /home/peter/src/swipl-devel/src/pl-read.c:4732 [0x7f7c7d7c1130]
33: [11] complex_term___LD() at /home/peter/src/swipl-devel/src/pl-read.c:4186 [0x7f7c7d7bc83a]
33: [12] read_term___LD() at /home/peter/src/swipl-devel/src/pl-read.c:4914 [0x7f7c7d7c28c3]
76: % [4/12] archive:create_and_open_named_no_close ........................ passed (0.953 sec)
33: [13] read_clause___LD() at /home/peter/src/swipl-devel/src/pl-read.c:5211 [0x7f7c7d7c4d7c]
33: [14] pl_read_clause3_va() at /home/peter/src/swipl-devel/src/pl-read.c:5242 [0x7f7c7d7c5207]
33: [15] PL_next_solution___LD() at /home/peter/src/swipl-devel/src/pl-vmi.c:4476 (discriminator 1) [0x7f7c7d579a40]
33: [16] callProlog() at /home/peter/src/swipl-devel/src/pl-pro.c:495 [0x7f7c7d749f7e]
33: [17] pl_sig_atomic1_va() at /home/peter/src/swipl-devel/src/pl-pro.c:393 [0x7f7c7d749361]
33: [18] PL_next_solution___LD() at /home/peter/src/swipl-devel/src/pl-vmi.c:4476 (discriminator 1) [0x7f7c7d579a40]
33: [19] callProlog() at /home/peter/src/swipl-devel/src/pl-pro.c:495 [0x7f7c7d749f7e]
33: [20] pl_sig_atomic1_va() at /home/peter/src/swipl-devel/src/pl-pro.c:393 [0x7f7c7d749361]
76: % [5/12] archive:create_and_open_named_twice_no_close .................. passed (0.761 sec)
33: [21] PL_next_solution___LD() at /home/peter/src/swipl-devel/src/pl-vmi.c:4476 (discriminator 1) [0x7f7c7d579a40]
33: [22] autoLoader() at /home/peter/src/swipl-devel/src/pl-proc.c:2986 [0x7f7c7d76d449]
33: [23] trapUndefined___LD() at /home/peter/src/swipl-devel/src/pl-proc.c:3029 [0x7f7c7d76da0c]
33: [24] getProcDefinedDefinition___LD() at /home/peter/src/swipl-devel/src/pl-wam.c:1611 [0x7f7c7d500a69]
33: [25] PL_next_solution___LD() at /home/peter/src/swipl-devel/src/pl-vmi.c:3316 (discriminator 1) [0x7f7c7d560e76]
33: [26] callProlog() at /home/peter/src/swipl-devel/src/pl-pro.c:495 [0x7f7c7d749f7e]
33: [27] pl_sig_atomic1_va() at /home/peter/src/swipl-devel/src/pl-pro.c:393 [0x7f7c7d749361]
76: % [6/12] archive:create_and_open_named_fail ............................ passed (0.779 sec)
33: [28] PL_next_solution___LD() at /home/peter/src/swipl-devel/src/pl-vmi.c:4476 (discriminator 1) [0x7f7c7d579a40]
33: [29] query_loop() at /home/peter/src/swipl-devel/src/pl-pro.c:147 [0x7f7c7d746bfc]
33: [30] prologToplevel() at /home/peter/src/swipl-devel/src/pl-pro.c:593 [0x7f7c7d74a76c]
33: [31] PL_initialise() at /home/peter/src/swipl-devel/src/pl-init.c:1316 [0x7f7c7d8dd278]
33: [32] /home/peter/src/swipl-devel/build.asan/src/swipl(+0x11e6) [0x55ff346c21e6]
33: [33] __libc_start_call_main() at ./csu/../sysdeps/x86/libc-start.c:74 [0x7f7c7c24624a]
76: % [7/12] archive:create_and_open_archive_entry ......................... passed (0.905 sec)
33: [34] call_init() at ./csu/../csu/libc-start.c:128 [0x7f7c7c246305]
33: [35] /home/peter/src/swipl-devel/build.asan/src/swipl(+0x10e1) [0x55ff346c20e1]
33: Last garbage collect at 474587 inferences
33: C-stack trace labeled "GC":
76: % [8/12] archive:create_and_open_archive_entry_no_close ................ passed (0.885 sec)
33: [0] __interceptor_backtrace.part.0() at /build/gcc-12-bTRWOB/gcc-12-12.2.0/build/x86_64-linux-gnu/libsanitizer/asan/../../../../src/libsanitizer/sanitizer_common/sanitizer_common_interceptors.inc:4277 [0x7f7c7ea51f31]
33: [1] save_backtrace() at /home/peter/src/swipl-devel/src/os/pl-cstack.c:335 [0x7f7c7db43352]
33: [2] garbageCollect() at /home/peter/src/swipl-devel/src/pl-gc.c:4423 [0x7f7c7d6c3042]
33: [3] f_ensureStackSpace___LD() at /home/peter/src/swipl-devel/src/pl-gc.c:4698 [0x7f7c7d6c6257]
33: [4] ensureStackSpace_ex___LD() at /home/peter/src/swipl-devel/src/pl-gc.h:121 [0x7f7c7d4efd23]
33: [5] PL_next_solution___LD() at /home/peter/src/swipl-devel/src/pl-vmi.c:1665 (discriminator 6) [0x7f7c7d53b7dd]
76: % [9/12] archive:create_and_open_archive_entry_no_close ................ passed (0.830 sec)
33: [6] callProlog() at /home/peter/src/swipl-devel/src/pl-pro.c:495 [0x7f7c7d749f7e]
76: % [10/12] archive:create_and_entries_error ............................. passed (0.010 sec)
33: [7] pl_sig_atomic1_va() at /home/peter/src/swipl-devel/src/pl-pro.c:393 [0x7f7c7d749361]
76: % [11/12] archive:bad_unify_blob ....................................... passed (0.007 sec)
76: % [12/12] archive:bad_mode ............................................. passed (0.003 sec)
33: [8] PL_next_solution___LD() at /home/peter/src/swipl-devel/src/pl-vmi.c:4476 (discriminator 1) [0x7f7c7d579a40]
33: [9] callProlog() at /home/peter/src/swipl-devel/src/pl-pro.c:495 [0x7f7c7d749f7e]
33: [10] pl_sig_atomic1_va() at /home/peter/src/swipl-devel/src/pl-pro.c:393 [0x7f7c7d749361]
33: [11] PL_next_solution___LD() at /home/peter/src/swipl-devel/src/pl-vmi.c:4476 (discriminator 1) [0x7f7c7d579a40]
33: [12] autoLoader() at /home/peter/src/swipl-devel/src/pl-proc.c:2986 [0x7f7c7d76d449]
33: [13] trapUndefined___LD() at /home/peter/src/swipl-devel/src/pl-proc.c:3029 [0x7f7c7d76da0c]
33: [14] PL_next_solution___LD() at /home/peter/src/swipl-devel/src/pl-vmi.c:5774 (discriminator 1) [0x7f7c7d5980da]
33: [15] callProlog() at /home/peter/src/swipl-devel/src/pl-pro.c:495 [0x7f7c7d749f7e]
33: [16] pl_with_output_to2_va() at /home/peter/src/swipl-devel/src/os/pl-file.c:1778 [0x7f7c7da82fc4]
2/86 Test #33: clib:crypt .......................SIGALRM***Exception: 45.34 sec
test 82
Start 82: jpl:java_in_prolog
82: Test command: /home/peter/src/swipl-devel/build.asan/src/swipl "-p" "foreign=:/home/peter/src/swipl-devel/build.asan/packages/plunit" "-f" "none" "--no-packs" "--on-error=status" "-s" "/home/peter/src/swipl-devel/packages/jpl/test_jpl.pl" "-g" "test_jpl" "-t" "halt"
82: Working Directory: /home/peter/src/swipl-devel/build.asan/packages/jpl
82: Test timeout computed to be: 10000000
76: % End unit archive: passed (8.068 sec CPU)
76: % All 12 tests passed in 10.352 seconds (10.323 cpu)
76: =================================================================
76: ==30341==ERROR: AddressSanitizer: heap-use-after-free on address 0x611000062b2c at pc 0x7fc8c627e92a bp 0x7ffc786ad130 sp 0x7ffc786ad128
76: READ of size 4 at 0x611000062b2c thread T0
76: #0 0x7fc8c627e929 in streamStatus /home/peter/src/swipl-devel/src/os/pl-file.c:1342
76: #1 0x7fc8c62791dd in PL_release_stream /home/peter/src/swipl-devel/src/os/pl-file.c:584
76: #2 0x7fc8c271e462 in libarchive_close_cb /home/peter/src/swipl-devel/packages/archive/archive4pl.c:365
76: #3 0x7fc8c0db1b98 (/lib/x86_64-linux-gnu/libarchive.so.13+0x24b98)
76: #4 0x7fc8c0db1abe (/lib/x86_64-linux-gnu/libarchive.so.13+0x24abe)
76: #5 0x7fc8c0db1b41 (/lib/x86_64-linux-gnu/libarchive.so.13+0x24b41)
76: #6 0x7fc8c0db1c17 (/lib/x86_64-linux-gnu/libarchive.so.13+0x24c17)
76: #7 0x7fc8c271db68 in archive_free_handle /home/peter/src/swipl-devel/packages/archive/archive4pl.c:266
76: #8 0x7fc8c271df89 in ar_w_release_cb /home/peter/src/swipl-devel/packages/archive/archive4pl.c:293
76: #9 0x7fc8c5ce5aaf in cleanupAtoms /home/peter/src/swipl-devel/src/pl-atom.c:1639
76: #10 0x7fc8c60df1bf in PL_cleanup /home/peter/src/swipl-devel/src/pl-init.c:1665
76: #11 0x7fc8c6260c65 in haltProlog /home/peter/src/swipl-devel/src/pl-fli.c:4683
76: #12 0x7fc8c6260ce2 in PL_halt /home/peter/src/swipl-devel/src/pl-fli.c:4695
76: #13 0x7fc8c5f3960d in pl_halt /home/peter/src/swipl-devel/src/pl-prims.c:5230
76: #14 0x7fc8c5d7a390 in PL_next_solution___LD /home/peter/src/swipl-devel/src/pl-vmi.c:4505
76: #15 0x7fc8c5f46bfb in query_loop /home/peter/src/swipl-devel/src/pl-pro.c:147
76: #16 0x7fc8c5f4a76b in prologToplevel /home/peter/src/swipl-devel/src/pl-pro.c:593
76: #17 0x7fc8c6260c2e in PL_toplevel /home/peter/src/swipl-devel/src/pl-fli.c:4650
76: #18 0x560ee44e11f8 in main /home/peter/src/swipl-devel/src/pl-main.c:143
76: #19 0x7fc8c4a46249 in __libc_start_call_main ../sysdeps/nptl/libc_start_call_main.h:58
76: #20 0x7fc8c4a46304 in __libc_start_main_impl ../csu/libc-start.c:360
76: #21 0x560ee44e10e0 in _start (/home/peter/src/swipl-devel/build.asan/src/swipl+0x10e0)
76:
76: 0x611000062b2c is located 44 bytes inside of 256-byte region [0x611000062b00,0x611000062c00)
76: freed by thread T0 here:
76: #0 0x7fc8c72b76a8 in __interceptor_free ../../../../src/libsanitizer/asan/asan_malloc_linux.cpp:52
76: #1 0x7fc8c62124f5 in PL_free /home/peter/src/swipl-devel/src/pl-alloc.c:1213
76: #2 0x7fc8c62df9f7 in unallocStream /home/peter/src/swipl-devel/src/os/pl-stream.c:2030
76: #3 0x7fc8c627991d in gc_close_stream /home/peter/src/swipl-devel/src/os/pl-file.c:702
76: #4 0x7fc8c6279e5e in release_stream_ref /home/peter/src/swipl-devel/src/os/pl-file.c:735
76: #5 0x7fc8c5ce5aaf in cleanupAtoms /home/peter/src/swipl-devel/src/pl-atom.c:1639
76: #6 0x7fc8c60df1bf in PL_cleanup /home/peter/src/swipl-devel/src/pl-init.c:1665
76: #7 0x7fc8c6260c65 in haltProlog /home/peter/src/swipl-devel/src/pl-fli.c:4683
76: #8 0x7fc8c6260ce2 in PL_halt /home/peter/src/swipl-devel/src/pl-fli.c:4695
76: #9 0x7fc8c5f3960d in pl_halt /home/peter/src/swipl-devel/src/pl-prims.c:5230
76: #10 0x7fc8c5d7a390 in PL_next_solution___LD /home/peter/src/swipl-devel/src/pl-vmi.c:4505
76: #11 0x7fc8c5f46bfb in query_loop /home/peter/src/swipl-devel/src/pl-pro.c:147
76: #12 0x7fc8c5f4a76b in prologToplevel /home/peter/src/swipl-devel/src/pl-pro.c:593
76: #13 0x7fc8c6260c2e in PL_toplevel /home/peter/src/swipl-devel/src/pl-fli.c:4650
76: #14 0x560ee44e11f8 in main /home/peter/src/swipl-devel/src/pl-main.c:143
76: #15 0x7fc8c4a46249 in __libc_start_call_main ../sysdeps/nptl/libc_start_call_main.h:58
76:
76: previously allocated by thread T0 here:
76: #0 0x7fc8c72b89cf in __interceptor_malloc ../../../../src/libsanitizer/asan/asan_malloc_linux.cpp:69
76: #1 0x7fc8c62123e3 in PL_malloc_uncollectable /home/peter/src/swipl-devel/src/pl-alloc.c:1142
76: #2 0x7fc8c62e8a49 in Snew /home/peter/src/swipl-devel/src/os/pl-stream.c:3321
76: #3 0x7fc8c62ea28c in Sopen_file /home/peter/src/swipl-devel/src/os/pl-stream.c:3547
76: #4 0x7fc8c6295841 in openStream /home/peter/src/swipl-devel/src/os/pl-file.c:4180
76: #5 0x7fc8c6296765 in pl_open44_va /home/peter/src/swipl-devel/src/os/pl-file.c:4253
76: #6 0x7fc8c5d79a3f in PL_next_solution___LD /home/peter/src/swipl-devel/src/pl-vmi.c:4476
76: #7 0x7fc8c5f49f7d in callProlog /home/peter/src/swipl-devel/src/pl-pro.c:495
76: #8 0x7fc8c6282fc3 in pl_with_output_to2_va /home/peter/src/swipl-devel/src/os/pl-file.c:1778
76: #9 0x7fc8c5d79a3f in PL_next_solution___LD /home/peter/src/swipl-devel/src/pl-vmi.c:4476
76: #10 0x7fc8c5f49f7d in callProlog /home/peter/src/swipl-devel/src/pl-pro.c:495
76: #11 0x7fc8c61ec6fd in pl_with_mutex /home/peter/src/swipl-devel/src/pl-mutex.c:765
76: #12 0x7fc8c5d7a8ce in PL_next_solution___LD /home/peter/src/swipl-devel/src/pl-vmi.c:4511
76: #13 0x7fc8c5f46bfb in query_loop /home/peter/src/swipl-devel/src/pl-pro.c:147
76: #14 0x7fc8c5f4a76b in prologToplevel /home/peter/src/swipl-devel/src/pl-pro.c:593
76: #15 0x7fc8c60dd277 in PL_initialise /home/peter/src/swipl-devel/src/pl-init.c:1316
76: #16 0x560ee44e11e5 in main /home/peter/src/swipl-devel/src/pl-main.c:139
76: #17 0x7fc8c4a46249 in __libc_start_call_main ../sysdeps/nptl/libc_start_call_main.h:58
76:
76: SUMMARY: AddressSanitizer: heap-use-after-free /home/peter/src/swipl-devel/src/os/pl-file.c:1342 in streamStatus
76: Shadow bytes around the buggy address:
76: 0x0c2280004510: fd fd fd fd fd fd fd fd fd fd fd fd fd fd fd fd
76: 0x0c2280004520: fd fd fd fd fd fd fd fd fd fd fd fd fd fd fd fd
76: 0x0c2280004530: fa fa fa fa fa fa fa fa fd fd fd fd fd fd fd fd
76: 0x0c2280004540: fd fd fd fd fd fd fd fd fd fd fd fd fd fd fd fd
76: 0x0c2280004550: fd fd fd fd fd fd fd fd fa fa fa fa fa fa fa fa
76: =>0x0c2280004560: fd fd fd fd fd[fd]fd fd fd fd fd fd fd fd fd fd
76: 0x0c2280004570: fd fd fd fd fd fd fd fd fd fd fd fd fd fd fd fd
76: 0x0c2280004580: fa fa fa fa fa fa fa fa fd fd fd fd fd fd fd fd
76: 0x0c2280004590: fd fd fd fd fd fd fd fd fd fd fd fd fd fd fd fd
76: 0x0c22800045a0: fd fd fd fd fd fd fd fd fa fa fa fa fa fa fa fa
76: 0x0c22800045b0: fd fd fd fd fd fd fd fd fd fd fd fd fd fd fd fd
76: Shadow byte legend (one shadow byte represents 8 application bytes):
76: Addressable: 00
76: Partially addressable: 01 02 03 04 05 06 07
76: Heap left redzone: fa
76: Freed heap region: fd
76: Stack left redzone: f1
76: Stack mid redzone: f2
76: Stack right redzone: f3
76: Stack after return: f5
76: Stack use after scope: f8
76: Global redzone: f9
76: Global init order: f6
76: Poisoned by user: f7
76: Container overflow: fc
76: Array cookie: ac
76: Intra object redzone: bb
76: ASan internal: fe
76: Left alloca redzone: ca
76: Right alloca redzone: cb
76: ==30341==ABORTING
3/86 Test #76: archive:archive ..................***Failed 48.26 sec
62: Test command: /home/peter/src/swipl-devel/build.asan/src/swipl "-p" "foreign=" "-f" "none" "--no-packs" "--on-error=status" "-s" "/home/peter/src/swipl-devel/packages/semweb/test_turtle.pl" "-g" "test_turtle" "-t" "halt"
62: Working Directory: /home/peter/src/swipl-devel/build.asan/packages/semweb
62: Test timeout computed to be: 10000000
55: % Start unit: py_mqi_fast
70: Seed: 472: /home/peter/src/swipl-devel/packages/semweb/rdf_db.c:1916:30: runtime error: left shift of 1 by 31 places cannot be represented in type 'int'
70: /home/peter/src/swipl-devel/packages/semweb/rdf_db.c:1906:21: runtime error: left shift of 1 by 31 places cannot be represented in type 'int'
82: % Start unit: jpl
62: % Turtle test 'bad-00.ttl': passed
62: % Turtle test 'bad-01.ttl': passed
62: % Turtle test 'bad-02.ttl': passed
62: % Turtle test 'bad-03.ttl': passed
62: % Turtle test 'bad-04.ttl': passed
62: % Turtle test 'bad-05.ttl': passed
62: % Turtle test 'bad-06.ttl': passed
62: % Turtle test 'bad-07.ttl': passed
62: % Turtle test 'bad-08.ttl': passed
62: % Turtle test 'bad-09.ttl': passed
62: % Turtle test 'bad-10.ttl': passed
62: % Turtle test 'bad-11.ttl': passed
62: % Turtle test 'bad-12.ttl': passed
62: % Turtle test 'bad-13.ttl': passed
62: % Turtle test 'bad-14.ttl': passed
62: % Turtle test 'base-00.ttl': passed
62: /home/peter/src/swipl-devel/src/pl-inline.h:144:46: runtime error: passing zero to clz(), which is not a valid argument
62: /home/peter/src/swipl-devel/src/pl-inline.h:144: runtime error: passing zero to clz(), which is not a valid argument
62: /home/peter/src/swipl-devel/src/pl-inline.h:144: runtime error: passing zero to clz(), which is not a valid argument
62: /home/peter/src/swipl-devel/src/pl-inline.h:144: runtime error: passing zero to clz(), which is not a valid argument
62: /home/peter/src/swipl-devel/src/pl-inline.h:144: runtime error: passing zero to clz(), which is not a valid argument
62: /home/peter/src/swipl-devel/src/pl-inline.h:144: runtime error: passing zero to clz(), which is not a valid argument
62: /home/peter/src/swipl-devel/src/pl-inline.h:144: runtime error: passing zero to clz(), which is not a valid argument
62: /home/peter/src/swipl-devel/src/pl-inline.h:144: runtime error: passing zero to clz(), which is not a valid argument
62: /home/peter/src/swipl-devel/src/pl-inline.h:144: runtime error: passing zero to clz(), which is not a valid argument
62: /home/peter/src/swipl-devel/src/pl-inline.h:144: runtime error: passing zero to clz(), which is not a valid argument
62: /home/peter/src/swipl-devel/src/pl-inline.h:144: runtime error: passing zero to clz(), which is not a valid argument
62: /home/peter/src/swipl-devel/src/pl-inline.h:144: runtime error: passing zero to clz(), which is not a valid argument
62: /home/peter/src/swipl-devel/src/pl-inline.h:144: runtime error: passing zero to clz(), which is not a valid argument
62: /home/peter/src/swipl-devel/src/pl-inline.h:144: runtime error: passing zero to clz(), which is not a valid argument
62: /home/peter/src/swipl-devel/src/pl-inline.h:144: runtime error: passing zero to clz(), which is not a valid argument
62: /home/peter/src/swipl-devel/src/pl-inline.h:144: runtime error: passing zero to clz(), which is not a valid argument
62: /home/peter/src/swipl-devel/src/pl-inline.h:144: runtime error: passing zero to clz(), which is not a valid argument
62: /home/peter/src/swipl-devel/src/pl-inline.h:144: runtime error: passing zero to clz(), which is not a valid argument
62: /home/peter/src/swipl-devel/src/pl-inline.h:144: runtime error: passing zero to clz(), which is not a valid argument
62: /home/peter/src/swipl-devel/src/pl-inline.h:144: runtime error: passing zero to clz(), which is not a valid argument
62: /home/peter/src/swipl-devel/src/pl-inline.h:144: runtime error: passing zero to clz(), which is not a valid argument
62: /home/peter/src/swipl-devel/src/pl-inline.h:144: runtime error: passing zero to clz(), which is not a valid argument
62: /home/peter/src/swipl-devel/src/pl-inline.h:144: runtime error: passing zero to clz(), which is not a valid argument
62: /home/peter/src/swipl-devel/src/pl-inline.h:144: runtime error: passing zero to clz(), which is not a valid argument
62: % Turtle test 'rdf-schema.ttl': passed
62: % Turtle test 'rdfq-results.ttl': passed
62: % Turtle test 'rdfs-namespace.ttl': passed
62: % Turtle test 'test-00.ttl': passed
62: % Turtle test 'test-01.ttl': passed
62: % Turtle test 'test-02.ttl': passed
62: % Turtle test 'test-03.ttl': passed
62: % Turtle test 'test-04.ttl': passed
62: % Turtle test 'test-05.ttl': passed
62: % Turtle test 'test-06.ttl': passed
62: % Turtle test 'test-07.ttl': passed
62: % Turtle test 'test-08.ttl': passed
62: % Turtle test 'test-09.ttl': passed
62: % Turtle test 'test-10.ttl': passed
62: % Turtle test 'test-11.ttl': passed
62: % Turtle test 'test-12.ttl': passed
62: % Turtle test 'test-13.ttl': passed
Pushed a couple of fixes that make building and testing clean using -fsanitize=undefined. It seems your sanitizer finds a couple more as I'm still using gcc-11 by default. Note that -fsanitize=address causes problems with these three packages. crypt and Java are not in our control. libarchive is probably a bug in cleanup. The archive binding is still not 100% robust when used improperly, e.g., not closing all resources ASAP.
Jan reminded me that there are still some ASAN problems with libarchive: https://github.com/SWI-Prolog/packages-archive/issues/16
I ran the tests with ASAN for the current image (dd7f4bdcaeec01f3c555d30a160de16195af190c) ... there seem to be some new ASAN errors that I hadn't seen before (including one in protobufs(!)). My guess is that there are one or two changes that have triggered these (e.g., in pl-trie.c), so if @jan can take a quick look first, that might eliminate quite a few of these. I've attempted to remove duplicates in the following log messages. If the following isn't sufficient to reproduce the problem, please tell me and I'll do a bit more digging.
8: % [3/10] monotonic_tabling:pb ../home/peter/src/swipl-devel/src/pl-trie.c:2053:43: runtime error: left shift of 1 by 31 places cannot be represented in type 'int'
8: % [10/23] trie:insert_vars .................................... passed (0.000 sec)
8: % [11/23] trie:rescale_cars ../home/peter/src/swipl-devel/src/pl-trie.c:552:14: runtime error: left shift of 1 by 31 places cannot be represented in type 'int'
8: % [20/23] trie:issue_1277 ..................................... passed (0.000 sec)
8: % [21/23] trie:gen_compiled2_free ../home/peter/src/swipl-devel/src/pl-gmp.c:797:25: runtime error: left shift of 255 by 24 places cannot be represented in type 'int'
8: /home/peter/src/swipl-devel/src/pl-gmp.c:801:16: runtime error: left shift of negative value -25
4: % [22/42] acyclic_terms:widely_nested_term_is_acyclic ......... passed (0.678 sec)
2: Running test set "gmp" ...................../home/peter/src/swipl-devel/src/pl-arith.c:1761:29: runtime error: shift exponent 2147483648 is too large for 64-bit type 'long int'
9: % [3/8] arithmetic_function:func .............................. passed (0.004 sec)
45: % [2/62] ffi:range2 ../home/peter/src/swipl-devel/src/pl-fli.c:4223:3: runtime error: left shift of negative value -1
3: % [20/21] reconsult:goal_expansion ............................ passed (0.121 sec)
2: ........................../home/peter/src/swipl-devel/src/pl-gmp.c:797:25: runtime error: left shift of 255 by 24 places cannot be represented in type 'int'
4: % [30/115] shift:shift_right_large ............................ passed (0.000 sec)
4: % [31/115] shift:shift_left_large ../home/peter/src/swipl-devel/src/pl-arith.c:1761:29: runtime error: left shift of negative value -1
9: % [3/3] expand_unit:expand .................................... passed (0.000 sec)
9: ./home/peter/src/swipl-devel/src/pl-inline.h:144:46: runtime error: passing zero to clz(), which is not a valid argument
9: /home/peter/src/swipl-devel/src/pl-inline.h:144: runtime error: passing zero to clz(), which is not a valid argument
9: /home/peter/src/swipl-devel/src/pl-inline.h:144: runtime error: passing zero to clz(), which is not a valid argument
59: % [9/54] some_message_example:some_message_wire ../home/peter/src/swipl-devel/packages/protobufs/protobufs.c:94:36: runtime error: left shift of negative value -666
69: Running test set "typed" .../home/peter/src/swipl-devel/packages/semweb/rdf_db.c:5577:9: runtime error: left shift of 16317 by 50 places cannot be represented in type 'long int'
70: Seed: 386: /home/peter/src/swipl-devel/packages/semweb/rdf_db.c:1916:30: runtime error: left shift of 1 by 31 places cannot be represented in type 'int'
69: Running test set "rdf_retractall" ./home/peter/src/swipl-devel/packages/semweb/rdf_db.c:4969:11: runtime error: null pointer passed as argument 2, which is declared to never be null
Thanks. On Ubuntu all was silent, but on Fedora I now have gcc 14, which confirms this. Pushed some fixes. Most is benign. It trapped a real bug in Prolog << and >> operators for shifting 0 by large amounts and forced me to clarify the behaviour for shifts of negative values and too large shifts, both being implementation defined in the standard.
Two are left, but I call it a day:
59: % [9/54] some_message_example:some_message_wire ../home/jan/src/swipl-devel/packages/protobufs/protobufs.c:94:36: runtime error: left shift of negative value -666
69: Running test set "typed" .../home/jan/src/swipl-devel/packages/semweb/rdf_db.c:5579:9: runtime error: left shift of 16317 by 50 places cannot be represented in type 'long int'
Confirmed on my system (gcc-12) that those are the only two errors.
Jan reminded me that there are still some ASAN problems with libarchive: SWI-Prolog/packages-archive#16
You can reproduce it "outside" the tests with these commands:
matthias@hp:~/swipl-devel/build$ src/swipl
Welcome to SWI-Prolog (threaded, 64 bits, version 9.3.6-6-gebed65495-DIRTY)
?- ['../packages/archive/test_archive.pl'].
?- test_archive:create_tmp_file("123.zip"),
test_archive:create_archive_file("123.zip", _SrcDir, _, _Ex).
?- halt.
(exits normally)
matthias@hp:~/swipl-devel/build$ src/swipl
Welcome to SWI-Prolog (threaded, 64 bits, version 9.3.6-6-gebed65495-DIRTY)
?- ['../packages/archive/test_archive.pl'].
?- test_archive:open_archive_entry("123.zip", _Ex, S),
close(S).
Ex = 'library/ext/archive/archive.pl',
S = <stream>(0x611000059f00).
?- halt.
=================================================================
==11907==ERROR: AddressSanitizer: heap-use-after-free on address 0x611000059dec at pc 0x7f3ac127c1ca bp 0x7fffcbd84170 sp 0x7fffcbd84168
READ of size 4 at 0x611000059dec thread T0
#0 0x7f3ac127c1c9 in streamStatus /home/matthias/swipl-devel/src/os/pl-file.c:1342
#1 0x7f3ac127c1c9 in PL_release_stream /home/matthias/swipl-devel/src/os/pl-file.c:584
#2 0x7f3abe8d935d in libarchive_close_cb /home/matthias/swipl-devel/packages/archive/archive4pl.c:365
etc.
close(S) is not needed.
Alternatively (assuming that 123.zip is in the current directory)
archive_open("123.zip", H, []).
halt. (crashes)
archive_open("123.zip", H, []), archive_close(H).
halt. (no crash)
Pushed a fix for the last two as well. Closing this. The libarchive issues are ASAN issues and have been discussed elsewhere anyway. They are related to the complicated dependency between the various handles that must be closed while the cleanup handlers are called in arbitrary order during cleanup. Note that only the debug build does the cleanup by default. For the release build, the user has to call PL_cleanup() to get this crash. While PL_cleanup() works with the core Prolog engine, many of the extension packs do not implement proper cleanup.