Open LocutusOfBorg opened 1 month ago
(gdb) bt full
#0 0x00007ffff78a3f1c in pthread_kill () from /lib/x86_64-linux-gnu/libc.so.6
No symbol table info available.
#1 0x00007ffff784519e in raise () from /lib/x86_64-linux-gnu/libc.so.6
No symbol table info available.
#2 0x00007ffff7828902 in abort () from /lib/x86_64-linux-gnu/libc.so.6
No symbol table info available.
#3 0x00007ffff782976c in ?? () from /lib/x86_64-linux-gnu/libc.so.6
No symbol table info available.
#4 0x00007ffff7941049 in __fortify_fail () from /lib/x86_64-linux-gnu/libc.so.6
No symbol table info available.
#5 0x00007ffff79409e4 in __chk_fail () from /lib/x86_64-linux-gnu/libc.so.6
No symbol table info available.
#6 0x00005555555bb50c in memset (__dest=<optimized out>, __ch=0, __len=<optimized out>) at /usr/include/x86_64-linux-gnu/bits/string_fortified.h:59
No locals.
#7 vclear<unsigned int> (ary=<optimized out>, n=<optimized out>) at /usr/src/spaln-3.0.2+dfsg-2/src/clib.h:105
No locals.
#8 ExinPot::calcScr_3(Seq const*, float*) const [clone .constprop.0] (this=this@entry=0x5555555f5370, sd=sd@entry=0x5555555f5ff0, scr=0x0) at /usr/src/spaln-3.0.2+dfsg-2/src/utilseq.cc:1458
redctab = 0x5555555ddd30 <tnredctab> "\004\004\004\001\002"
len = <optimized out>
ss = <optimized out>
tt = <optimized out>
cdp = 0x555555609d00
result = 0x555555678370
rest = <optimized out>
kk = 6
x = <optimized out>
buf = {8838, 6696, 2208}
w = <optimized out>
acc = 0
#9 0x0000555555575618 in ExinPot::calcScr (scr=0x0, this=0x5555555f5370, sd=<optimized out>) at /usr/src/spaln-3.0.2+dfsg-2/src/utilseq.h:161
No locals.
#10 Exinon::intron53_p (this=0x55555564c240, dvsp=true) at /usr/src/spaln-3.0.2+dfsg-2/src/codepot.cc:543
th5 = <optimized out>
posB = <optimized out>
last = <optimized out>
prefS = <optimized out>
prfS = <optimized out>
fs = <optimized out>
fT = <optimized out>
fB = 0
prefT = 0x555555673360
prefB = 0x0
prfT = <optimized out>
prfB = <optimized out>
fI = <optimized out>
fO = -300
thB = <optimized out>
pref3 = 0x555555669340
prefI = <optimized out>
prf3 = <optimized out>
prfI = <optimized out>
th3 = <optimized out>
ss = <optimized out>
wk53 = <optimized out>
fE = <optimized out>
pref5 = 0x555555664330
prefE = <optimized out>
prf5 = <optimized out>
prfE = <optimized out>
sigB = <optimized out>
fE = <optimized out>
fI = <optimized out>
fT = <optimized out>
fB = <optimized out>
fO = <optimized out>
th3 = <optimized out>
th5 = <optimized out>
thB = <optimized out>
pref5 = <optimized out>
pref3 = <optimized out>
prefS = <optimized out>
prefT = <optimized out>
prefB = <optimized out>
prefE = <optimized out>
prefI = <optimized out>
prf5 = <optimized out>
prf3 = <optimized out>
prfS = <optimized out>
prfT = <optimized out>
prfB = <optimized out>
prfE = <optimized out>
prfI = <optimized out>
ss = <optimized out>
sigB = <optimized out>
posB = <optimized out>
last = <optimized out>
wk53 = <optimized out>
fs = <optimized out>
wkb = <optimized out>
sig5 = <optimized out>
sig3 = <optimized out>
sigE = <optimized out>
sigb = <optimized out>
#11 Exinon::Exinon (this=<optimized out>, sd_=<optimized out>, pwd_=<optimized out>, bo=<optimized out>, this=<optimized out>, sd_=<optimized out>, pwd_=<optimized out>, bo=<optimized out>)
at /usr/src/spaln-3.0.2+dfsg-2/src/codepot.cc:396
zero53 = {dinc5 = 0, dinc3 = 0, cano5 = 0, cano3 = 0}
zero53 = <optimized out>
prefE = <optimized out>
prfE = <optimized out>
fE = <optimized out>
wkb = <optimized out>
#12 0x000055555555fb74 in genomicseq (sqs=sqs@entry=0x5555555f5998, pwd=pwd@entry=0x5555555f52b0, ori=ori@entry=1) at /usr/src/spaln-3.0.2+dfsg-2/src/spaln.cc:1120
No locals.
#13 0x0000555555563809 in spalign2 (sqs=0x5555555f5990, pwd=0x5555555f52b0, GsI=0x555555609058, ori=1) at /usr/src/spaln-3.0.2+dfsg-2/src/spaln.cc:664
No locals.
#14 0x00005555555c5b7c in blkaln(Seq**, SrchBlk*, RANGE*, ThQueue*) [clone .isra.0] (sqs=<optimized out>, bks=<optimized out>, q=<optimized out>, rng=<optimized out>)
at /usr/src/spaln-3.0.2+dfsg-2/src/spaln.cc:891
dir = <optimized out>
sigb = <optimized out>
#11 Exinon::Exinon (this=<optimized out>, sd_=<optimized out>, pwd_=<optimized out>, bo=<optimized out>, this=<optimized out>, sd_=<optimized out>, pwd_=<optimized out>, bo=<optimized out>)
at /usr/src/spaln-3.0.2+dfsg-2/src/codepot.cc:396
zero53 = {dinc5 = 0, dinc3 = 0, cano5 = 0, cano3 = 0}
zero53 = <optimized out>
prefE = <optimized out>
prfE = <optimized out>
fE = <optimized out>
wkb = <optimized out>
#12 0x000055555555fb74 in genomicseq (sqs=sqs@entry=0x5555555f5998, pwd=pwd@entry=0x5555555f52b0, ori=ori@entry=1) at /usr/src/spaln-3.0.2+dfsg-2/src/spaln.cc:1120
No locals.
#13 0x0000555555563809 in spalign2 (sqs=0x5555555f5990, pwd=0x5555555f52b0, GsI=0x555555609058, ori=1) at /usr/src/spaln-3.0.2+dfsg-2/src/spaln.cc:664
No locals.
#14 0x00005555555c5b7c in blkaln(Seq**, SrchBlk*, RANGE*, ThQueue*) [clone .isra.0] (sqs=<optimized out>, bks=<optimized out>, q=<optimized out>, rng=<optimized out>)
at /usr/src/spaln-3.0.2+dfsg-2/src/spaln.cc:891
dir = <optimized out>
--Type <RET> for more, q to quit, c to continue without paging--
n = <optimized out>
nparalog = <optimized out>
grng = <optimized out>
wrng = <optimized out>
frng = <optimized out>
a = <optimized out>
b = <optimized out>
b_intr = <optimized out>
hfg = {left = 0, right = 2147483647, segno = 0, sname = 0x0}
GsI = 0x555555609058
gsinf = <optimized out>
n_out = <optimized out>
gener = <optimized out>
basis = <optimized out>
odr = <optimized out>
#15 0x00005555555c3a03 in quick4(Seq**, SrchBlk*, ThQueue*) [clone .isra.0] (sqs=0x5555555f5990, bks=0x5555555f5100, q=0x0) at /usr/src/spaln-3.0.2+dfsg-2/src/spaln.cc:1095
a = @0x5555555f5990: 0x5555555f59e0
orgrng = <optimized out>
covrng = <optimized out>
rbdry = <optimized out>
#16 0x0000555555567065 in all_in_func (sqs=0x5555555f5990, svr=0x7fffffffddf0, prm=0x5555555f5100) at /usr/src/spaln-3.0.2+dfsg-2/src/spaln.cc:1167
nf = 0
sbk = <optimized out>
#17 0x000055555555d9a4 in main (argc=1, argv=0x7fffffffe788) at /usr/src/spaln-3.0.2+dfsg-2/src/spaln.cc:1562
bprm = 0x5555555f5100
messg = 0x0
insuf = 0x5555555c91c0 "No input seq file !\n"
n = <optimized out>
nseqs = 8
seqs = 0x5555555f5990
a = @0x5555555f5990: 0x5555555f59e0
b = @0x5555555f5998: 0x5555555f5ff0
mb = <optimized out>
dbs = <optimized out>
svr = {argc = 0, argc0 = 1, argv = 0x7fffffffe790, argv0 = 0x7fffffffe788, fd = {0x0, 0x0}, gzfd = {0x5555555f56b0, 0x0}, fc = 0x0, nfrom = {0, 0}, nto = {2147483647, 2147483647}, cfrom = {0x0, 0x0},
cto = {0x0, 0x0}, counter = {1, 0}, sw = {true, false}, molc = {1, 0}, attr = {0x5555555f49a0 " SP", 0x0}, atsz = {8, 0}, input_form = IM_SNGL, input_ns = 1, target_dbf = 0x5555555f12b0,
query_dbf = 0x0}
the failure is in vclear function
vclear
Since I don't fully understand your code, I asked chatGPT to analyze it:
To fix the function ExinPot::calcScr_3 to correctly calculate the coding potential from a DNA sequence based on a 5th-order Markov model, we need to address several issues in the code:
Key Fixes Needed: Memory Alignment: Align pointers correctly to avoid accessing out-of-bounds memory. Buffer Management: Ensure that the buffer accesses are within bounds. Initialization: Properly initialize variables to avoid undefined behavior. Correct Markov Calculation: Make sure the logic for computing values based on the 5th-order Markov model is correct. Correct Length Calculation for vclear: Ensure the vclear function call correctly clears the necessary range of data. Here's a corrected and more robust implementation of the function:
and this is the patch
--- spaln-3.0.2+dfsg.orig/src/utilseq.cc
+++ spaln-3.0.2+dfsg/src/utilseq.cc
@@ -1429,7 +1429,7 @@ const CHAR* tt = sd->at(sd->right);
const float* cdp = begin();
float* result = new float[len];
- float* rest = result - 5;
+ float* rest = result;
const int kk = morder + 1;
int x = kk;
int buf[3] = {0, 0, 0};
@@ -1438,19 +1438,19 @@ double acc = 0.;
for (int p = 1; ss < tt; p = next_p[p], ++rest) {
int c = redctab[*ss++];
if (c < 4) {
- buf[p] = 3 * (w = (4 * w + c) % ndata);
- if (x) --x;
+ buf[p % 3] = 3 * (w = (4 * w + c) % ndata);
+ if (x > 0) --x;
} else {
w = 0;
x = kk;
}
float val = 0;
- if (!x) {
- val += cdp[buf[next_p[p]] + 2]; // -1
- val += cdp[buf[prev_p[p]]]; // 0
- val += cdp[buf[p] + 1]; // +1
+ if (x == 0) {
+ val += cdp[buf[next_p[p % 3]] + 2]; // -1
+ val += cdp[buf[prev_p[p % 3]]]; // 0
+ val += cdp[buf[p % 3] + 1]; // +1
}
- if (rest >= result) {
+ if (rest < result + len) {
*rest = val;
if (scr && p == 1) acc += val;
}
that made tests pass and no segfault happen Key Changes Made: Pointer Alignment: rest is initialized as result to avoid out-of-bounds memory access. Buffer Indexing: The buffer index p is wrapped with modulo operation to prevent out-of-bounds access. Initialization: All necessary variables are initialized correctly to avoid undefined behaviors. Correct Length in vclear: The range passed to vclear is corrected to ensure proper clearing of the result array. Error Checking and Safety: Additional checks ensure that the pointers remain within bounds during processing. This version of the function should properly calculate the coding potential of a DNA sequence using a 5th-order Markov model, while adhering to proper C++ practices to avoid memory errors.
Dear Gianfranco,
Thank you for your comments.
The crash is likely to be caused by a simple bug at reading gzipped query sequences. I have uploaded a fixed version today. Please try the new version whether it is still problematic in your system.
As for coding potential, I will look at the code again according to your suggestions.
Osamu,
Hello, unfortunately your commit 6ffcd906466a2f75bbde5ba6731d3a3a60c90111 looks not enough to fix the issue
#0 0x00007ffff78a3f1c in pthread_kill () from /lib/x86_64-linux-gnu/libc.so.6
No symbol table info available.
#1 0x00007ffff784519e in raise () from /lib/x86_64-linux-gnu/libc.so.6
No symbol table info available.
#2 0x00007ffff7828902 in abort () from /lib/x86_64-linux-gnu/libc.so.6
No symbol table info available.
#3 0x00007ffff782976c in ?? () from /lib/x86_64-linux-gnu/libc.so.6
No symbol table info available.
#4 0x00007ffff7941049 in __fortify_fail () from /lib/x86_64-linux-gnu/libc.so.6
No symbol table info available.
#5 0x00007ffff79409e4 in __chk_fail () from /lib/x86_64-linux-gnu/libc.so.6
No symbol table info available.
#6 0x00005555555bb50c in memset (__dest=<optimized out>, __ch=0, __len=<optimized out>) at /usr/include/x86_64-linux-gnu/bits/string_fortified.h:59
No locals.
#7 vclear<unsigned int> (ary=<optimized out>, n=<optimized out>) at /usr/src/spaln-3.0.2+dfsg-2ubuntu3/src/clib.h:105
No locals.
#8 ExinPot::calcScr_3(Seq const*, float*) const [clone .constprop.0] (this=this@entry=0x5555555f5480, sd=sd@entry=0x5555555f5ff0, scr=0x0) at /usr/src/spaln-3.0.2+dfsg-2ubuntu3/src/utilseq.cc:1458
redctab = 0x5555555ddd30 <tnredctab> "\004\004\004\001\002"
len = <optimized out>
ss = <optimized out>
tt = <optimized out>
cdp = 0x555555609d00
result = 0x555555678470
rest = <optimized out>
kk = 6
x = <optimized out>
buf = {8838, 6696, 2208}
w = <optimized out>
acc = 0
#9 0x0000555555575618 in ExinPot::calcScr (scr=0x0, this=0x5555555f5480, sd=<optimized out>) at /usr/src/spaln-3.0.2+dfsg-2ubuntu3/src/utilseq.h:161
No locals.
#10 Exinon::intron53_p (this=0x55555564c340, dvsp=true) at /usr/src/spaln-3.0.2+dfsg-2ubuntu3/src/codepot.cc:543
th5 = <optimized out>
posB = <optimized out>
last = <optimized out>
prefS = <optimized out>
prfS = <optimized out>
fs = <optimized out>
fT = <optimized out>
fB = 0
prefT = 0x555555673460
prefB = 0x0
prfT = <optimized out>
prfB = <optimized out>
fI = <optimized out>
fO = -300
thB = <optimized out>
pref3 = 0x555555669440
prefI = <optimized out>
prf3 = <optimized out>
prfI = <optimized out>
th3 = <optimized out>
ss = <optimized out>
wk53 = <optimized out>
fE = <optimized out>
pref5 = 0x555555664430
prefE = <optimized out>
prf5 = <optimized out>
prfE = <optimized out>
sigB = <optimized out>
fE = <optimized out>
fI = <optimized out>
fT = <optimized out>
fB = <optimized out>
fO = <optimized out>
th3 = <optimized out>
th5 = <optimized out>
thB = <optimized out>
pref5 = <optimized out>
pref3 = <optimized out>
prefS = <optimized out>
prefT = <optimized out>
prefB = <optimized out>
prefE = <optimized out>
prefI = <optimized out>
prf5 = <optimized out>
prf3 = <optimized out>
prfS = <optimized out>
prfT = <optimized out>
prfB = <optimized out>
prfE = <optimized out>
prfI = <optimized out>
ss = <optimized out>
sigB = <optimized out>
posB = <optimized out>
last = <optimized out>
wk53 = <optimized out>
fs = <optimized out>
wkb = <optimized out>
sig5 = <optimized out>
sig3 = <optimized out>
sigE = <optimized out>
sigb = <optimized out>
#11 Exinon::Exinon (this=<optimized out>, sd_=<optimized out>, pwd_=<optimized out>, bo=<optimized out>, this=<optimized out>, sd_=<optimized out>, pwd_=<optimized out>, bo=<optimized out>)
at /usr/src/spaln-3.0.2+dfsg-2ubuntu3/src/codepot.cc:396
zero53 = {dinc5 = 0, dinc3 = 0, cano5 = 0, cano3 = 0}
zero53 = <optimized out>
prefE = <optimized out>
prfE = <optimized out>
fE = <optimized out>
wkb = <optimized out>
#12 0x000055555555fb74 in genomicseq (sqs=sqs@entry=0x5555555f5998, pwd=pwd@entry=0x5555555f53c0, ori=ori@entry=1) at /usr/src/spaln-3.0.2+dfsg-2ubuntu3/src/spaln.cc:1120
No locals.
#13 0x0000555555563809 in spalign2 (sqs=0x5555555f5990, pwd=0x5555555f53c0, GsI=0x555555617348, ori=1) at /usr/src/spaln-3.0.2+dfsg-2ubuntu3/src/spaln.cc:664
No locals.
#14 0x00005555555c5b7c in blkaln(Seq**, SrchBlk*, RANGE*, ThQueue*) [clone .isra.0] (sqs=<optimized out>, bks=<optimized out>, q=<optimized out>, rng=<optimized out>)
at /usr/src/spaln-3.0.2+dfsg-2ubuntu3/src/spaln.cc:891
dir = <optimized out>
n = <optimized out>
nparalog = <optimized out>
grng = <optimized out>
wrng = <optimized out>
frng = <optimized out>
a = <optimized out>
b = <optimized out>
b_intr = <optimized out>
hfg = {left = 0, right = 2147483647, segno = 0, sname = 0x0}
GsI = 0x555555617348
gsinf = <optimized out>
n_out = <optimized out>
gener = <optimized out>
basis = <optimized out>
odr = <optimized out>
#15 0x00005555555c3a03 in quick4(Seq**, SrchBlk*, ThQueue*) [clone .isra.0] (sqs=0x5555555f5990, bks=0x5555555f5210, q=0x0) at /usr/src/spaln-3.0.2+dfsg-2ubuntu3/src/spaln.cc:1095
a = @0x5555555f5990: 0x5555555f59e0
orgrng = <optimized out>
covrng = <optimized out>
rbdry = <optimized out>
#16 0x0000555555567065 in all_in_func (sqs=0x5555555f5990, svr=0x7fffffffddf0, prm=0x5555555f5210) at /usr/src/spaln-3.0.2+dfsg-2ubuntu3/src/spaln.cc:1167
nf = 0
sbk = <optimized out>
#17 0x000055555555d9a4 in main (argc=1, argv=0x7fffffffe788) at /usr/src/spaln-3.0.2+dfsg-2ubuntu3/src/spaln.cc:1562
bprm = 0x5555555f5210
messg = 0x0
insuf = 0x5555555c91c0 "No input seq file !\n"
n = <optimized out>
nseqs = 8
seqs = 0x5555555f5990
a = @0x5555555f5990: 0x5555555f59e0
b = @0x5555555f5998: 0x5555555f5ff0
mb = <optimized out>
dbs = <optimized out>
svr = {argc = 0, argc0 = 1, argv = 0x7fffffffe790, argv0 = 0x7fffffffe788, fd = {0x0, 0x0}, gzfd = {0x5555555f56b0, 0x0}, fc = 0x0, nfrom = {0, 0}, nto = {2147483647, 2147483647}, cfrom = {0x0,
0x0}, cto = {0x0, 0x0}, counter = {1, 0}, sw = {true, false}, molc = {1, 0}, attr = {0x5555555f49a0 " SP", 0x0}, atsz = {8, 0}, input_form = IM_SNGL, input_ns = 1,
target_dbf = 0x5555555f12b0, query_dbf = 0x0}
Hello, I found spaln crashing on this command, when -D_FORTIFY_SOURCE=3 is used during build
345s autopkgtest [20:14:46]: test run-unit-test: [----------------------- 346s Gd:187913 No:71174 My:3057 MS:157 Mb:188 Tw:2331733 Tl:33850852 71.68 1.17 27.15 347s #Segs 6630, TabSize 262144, Words: 2331733, GenomeSize 33928503, GIDs 6 354s Gd:4336377 No:59650673 My:12950 MS:365 Mb:69 Tw:6664558 Tl:44608849 6.78 0.02 93.20 356s #Segs 6630, TabSize 64000000, Words: 6664558, GenomeSize 33928503, GIDs 6 358s buffer overflow detected : terminated 372s /tmp/autopkgtest.xYGgJE/build.dZa/src/debian/tests/run-unit-test: line 23: 2420 Aborted (core dumped) spaln -Q7 -d dictdisc_g -T dictdisc dictdisc.faa.gz > /dev/null 372s autopkgtest [20:15:13]: test run-unit-test: -----------------------] 379s run-unit-test FAIL non-zero exit status 134
this is the testsuite content
and this is how the package is built (Ubuntu enforces FORTIFY_SOURCE=3 by default) https://launchpadlibrarian.net/748233307/buildlog_ubuntu-oracular-amd64.spaln_3.0.2+dfsg-2build2_BUILDING.txt.gz
x86_64-linux-gnu-g++ -g -O2 -Werror=implicit-function-declaration -fno-omit-frame-pointer -mno-omit-leaf-frame-pointer -ffile-prefix-map=/<>=. -flto=auto -ffat-lto-objects -fstack-protector-strong -fstack-clash-protection -Wformat -Werror=format-security -fcf-protection -fdebug-prefix-map=/<>=/usr/src/spaln-3.0.2+dfsg-2build2 -pedantic -Wdate-time -D_FORTIFY_SOURCE=3 -DM_THREAD=1 -c blksrc.cc
x86_64-linux-gnu-g++ -g -O2 -Werror=implicit-function-declaration -fno-omit-frame-pointer -mno-omit-leaf-frame-pointer -ffile-prefix-map=/<>=. -flto=auto -ffat-lto-objects -fstack-protector-strong -fstack-clash-protection -Wformat -Werror=format-security -fcf-protection -fdebug-prefix-map=/<>=/usr/src/spaln-3.0.2+dfsg-2build2 -pedantic -Wdate-time -D_FORTIFY_SOURCE=3 -DM_THREAD=1 -c aln2.cc
x86_64-linux-gnu-g++ -g -O2 -Werror=implicit-function-declaration -fno-omit-frame-pointer -mno-omit-leaf-frame-pointer -ffile-prefix-map=/<>=. -flto=auto -ffat-lto-objects -fstack-protector-strong -fstack-clash-protection -Wformat -Werror=format-security -fcf-protection -fdebug-prefix-map=/<>=/usr/src/spaln-3.0.2+dfsg-2build2 -pedantic -Wdate-time -D_FORTIFY_SOURCE=3 -DM_THREAD=1 -c dbs.cc
x86_64-linux-gnu-g++ -g -O2 -Werror=implicit-function-declaration -fno-omit-frame-pointer -mno-omit-leaf-frame-pointer -ffile-prefix-map=/<>=. -flto=auto -ffat-lto-objects -fstack-protector-strong -fstack-clash-protection -Wformat -Werror=format-security -fcf-protection -fdebug-prefix-map=/<>=/usr/src/spaln-3.0.2+dfsg-2build2 -pedantic -Wdate-time -D_FORTIFY_SOURCE=3 -DM_THREAD=1 -c gaps.cc