Dear Maintainer,
the original staden-io-lib seems to be built with
libhtscodecs2 in version 1.2.2-1 [1].

The rebuild seems to be using libhtscodecs2 in version 1.3.0-4.

Unfortunately htscodecs upstream integrated this commit [3],
which renamed e.g. function encode_names to tok3_encode_names.
It added a compatibility function encode_names, but does not
declare it in the header file.
Therefore in the build of staden-io-lib the function encode_names
is implicitly declared - therefore seems to default to
a return type of int [4] - and therefore the returned pointer
gets truncated to the lower 4 bytes [5].
This get through unnoticed until the pointer is freed and
produces a segfault there [6].

I guess the right thing would be to have the short function name
in the header file of htscodecs, therefore solve this issue for
other packages using htscodecs.

A short term solution might be the patch in [7] which makes
the build and tests succeed without "implicit declarations".

Kind regards,
Bernhard



[1] 
https://buildd.debian.org/status/fetch.php?pkg=staden-io-lib&arch=amd64&ver=1.14.14%2Bdfsg-1%2Bb1&stamp=1663567926&raw=0
[2] https://tracker.debian.org/pkg/htscodecs
[3] 
https://github.com/jkbonfield/htscodecs/commit/6211b208d2bd21e93f3f62c0cd0d8c43546f98b5

[4]
    cram_io.c: In function ‘cram_compress_by_method’:
    cram_io.c:2420:23: warning: implicit declaration of function 
‘encode_names’; did you mean ‘tok3_encode_names’? 
[-Wimplicit-function-declaration]
    2420 |         uint8_t *cp = encode_names(in, in_size, lev, strat, 
&out_len, NULL);
        |                       ^~~~~~~~~~~~
        |                       tok3_encode_names
    cram_io.c:2420:23: warning: initialization of ‘uint8_t *’ {aka ‘unsigned 
char *’} from ‘int’ makes pointer from integer without a cast [-Wint-conversion]


[5]
    (rr) bt
    #0  tok3_encode_names (blk=<optimized out>, len=<optimized out>, level=<optimized out>, 
use_arith=<optimized out>, out_len=<optimized out>, last_start_p=<optimized out>) at 
./htscodecs/tokenise_name3.c:1540
    #1  0x00007f281aa34454 in cram_compress_by_method (s=s@entry=0x55e9af757e50, in=0x7f281000e930 
"s0", in_size=9, out_size=out_size@entry=0x7f2819611730, method=method@entry=TOK3, 
level=<optimized out>, strat=0, content_id=<optimized out>) at ./io_lib/cram_io.c:2420
    #2  0x00007f281aa38ebe in cram_compress_block (fd=fd@entry=0x55e9af71f930, 
s=s@entry=0x55e9af757e50, b=0x55e9af758830, metrics=0x55e9af731f50, 
method=65794, level=level@entry=5) at ./io_lib/cram_io.c:2562
    #3  0x00007f281aa22d75 in cram_compress_slice (s=0x55e9af757e50, c=<optimized 
out>, fd=0x55e9af71f930) at ./io_lib/cram_encode.c:951
    #4  cram_encode_slice (fd=fd@entry=0x55e9af71f930, 
c=c@entry=0x55e9af73c270, h=h@entry=0x55e9af73c520, s=0x55e9af757e50) at 
./io_lib/cram_encode.c:1219
    #5  0x00007f281aa27881 in cram_encode_container (fd=<optimized out>, 
c=<optimized out>) at ./io_lib/cram_encode.c:2119
    #6  0x00007f281aa33fb0 in cram_flush_thread (arg=0x55e9af4d0500) at 
./io_lib/cram_io.c:4328
    #7  0x00007f281aa44272 in t_pool_worker (arg=0x55e9af737460) at 
./io_lib/thread_pool.c:434
    #8  0x00007f281a68784a in start_thread (arg=<optimized out>) at 
./nptl/pthread_create.c:442
    #9  0x00007f281a70a530 in clone () at 
../sysdeps/unix/sysv/linux/x86_64/clone.S:100
    (rr) print out
    $6 = (uint8_t *) 0x7f2810010320 "\t"
    (rr) finish
    Run till exit from #0  tok3_encode_names (blk=<optimized out>, len=<optimized out>, 
level=<optimized out>, use_arith=<optimized out>, out_len=<optimized out>, 
last_start_p=<optimized out>) at ./htscodecs/tokenise_name3.c:1540
    0x00007f281aa34454 in cram_compress_by_method (s=s@entry=0x55e9af757e50, in=0x7f281000e930 
"s0", in_size=9, out_size=out_size@entry=0x7f2819611730, method=method@entry=TOK3, 
level=<optimized out>, strat=0, content_id=<optimized out>) at ./io_lib/cram_io.c:2420
    2420            uint8_t *cp = encode_names(in, in_size, lev, strat, 
&out_len, NULL);
    Value returned is $8 = (uint8_t *) 0x7f2810010320 "\t"
    (rr) stepi
    2421            *out_size = out_len;
    (rr) print cp
    $7 = (uint8_t *) 0x10010320 <error: Cannot access memory at address 
0x10010320>
    (rr) list
    2416            int out_len;
    2417            int lev = level;
    2418            if (method == NAME_TOK3 && lev > 3)
    2419                lev = 3;
    2420            uint8_t *cp = encode_names(in, in_size, lev, strat, 
&out_len, NULL);
    2421            *out_size = out_len;
    2422            return (char *)cp;
    2423        }
    2424
    2425        case RAW:


[6]
    Thread 2 received signal SIGSEGV, Segmentation fault.
    0x00007f281a69788a in __GI___libc_free (mem=0x10010320) at 
./malloc/malloc.c:3363
    3363    ./malloc/malloc.c: Datei oder Verzeichnis nicht gefunden.
    (rr) bt
    #0  0x00007f281a69788a in __GI___libc_free (mem=0x10010320) at 
./malloc/malloc.c:3363
    #1  0x00007f281aa39238 in cram_compress_block (fd=fd@entry=0x55e9af71f930, 
s=s@entry=0x55e9af757e50, b=0x55e9af758830, metrics=0x55e9af731f50, 
method=65794, level=level@entry=5) at ./io_lib/cram_io.c:2575
    #2  0x00007f281aa22d75 in cram_compress_slice (s=0x55e9af757e50, c=<optimized 
out>, fd=0x55e9af71f930) at ./io_lib/cram_encode.c:951
    #3  cram_encode_slice (fd=fd@entry=0x55e9af71f930, 
c=c@entry=0x55e9af73c270, h=h@entry=0x55e9af73c520, s=0x55e9af757e50) at 
./io_lib/cram_encode.c:1219
    #4  0x00007f281aa27881 in cram_encode_container (fd=<optimized out>, 
c=<optimized out>) at ./io_lib/cram_encode.c:2119
    #5  0x00007f281aa33fb0 in cram_flush_thread (arg=0x55e9af4d0500) at 
./io_lib/cram_io.c:4328
    #6  0x00007f281aa44272 in t_pool_worker (arg=0x55e9af737460) at 
./io_lib/thread_pool.c:434
    #7  0x00007f281a68784a in start_thread (arg=<optimized out>) at 
./nptl/pthread_create.c:442
    #8  0x00007f281a70a530 in clone () at 
../sysdeps/unix/sysv/linux/x86_64/clone.S:100
    (rr) print mem
    $10 = (void *) 0x10010320
    (rr) up
    #1  0x00007f281aa39238 in cram_compress_block (fd=fd@entry=0x55e9af71f930, 
s=s@entry=0x55e9af757e50, b=0x55e9af758830, metrics=0x55e9af731f50, 
method=65794, level=level@entry=5) at ./io_lib/cram_io.c:2575
    2575                            free(c);
    (rr) list
    2570                            method_best = m;
    2571                            if (c_best)
    2572                                free(c_best);
    2573                            c_best = c;
    2574                        } else if (c) {
    2575                            free(c);
    2576                        } else {
    2577                            sz[m] = b->uncomp_size*2+1000; // 
arbitrarily worse than raw
    2578                        }
    2579


[7]
    --- staden-io-lib-1.14.14+dfsg.orig/io_lib/cram_codecs.c
    +++ staden-io-lib-1.14.14+dfsg/io_lib/cram_codecs.c
    @@ -1970,10 +1970,10 @@ static int cram_xrle_decode_expand_char(
        int nb = var_get_u64(len_dat, len_dat+len_sz, &out_sz);
        if (!(b->data = malloc(out_sz)))
            return -1;
    -    rle_decode(lit_dat, lit_sz,
    -              len_dat+nb, len_sz-nb,
    -              rle_syms, rle_nsyms,
    -              b->data, &out_sz);
    +    hts_rle_decode(lit_dat, lit_sz,
    +                   len_dat+nb, len_sz-nb,
    +                   rle_syms, rle_nsyms,
    +                   b->data, &out_sz);
        b->uncomp_size = out_sz;
return 0;
    @@ -2139,10 +2139,10 @@ int cram_xrle_encode_flush(cram_codec *c
int nb = var_put_u64(out_len, NULL, c->e_xrle.to_flush_size); - out_lit = rle_encode((uint8_t *)c->e_xrle.to_flush, c->e_xrle.to_flush_size,
    -                        out_len+nb, &out_len_size,
    -                        rle_syms, &rle_nsyms,
    -                        NULL, &out_lit_size);
    +    out_lit = hts_rle_encode((uint8_t *)c->e_xrle.to_flush, 
c->e_xrle.to_flush_size,
    +                             out_len+nb, &out_len_size,
    +                             rle_syms, &rle_nsyms,
    +                             NULL, &out_lit_size);
        out_len_size += nb;
--- staden-io-lib-1.14.14+dfsg.orig/io_lib/cram_io.c
    +++ staden-io-lib-1.14.14+dfsg/io_lib/cram_io.c
    @@ -2162,7 +2162,7 @@ int cram_uncompress_block(cram_block *b)
case NAME_TOK3: {
            uint32_t out_len;
    -       uint8_t *cp = decode_names(b->data, b->comp_size, &out_len);
    +       uint8_t *cp = tok3_decode_names(b->data, b->comp_size, &out_len);
            b->orig_method = NAME_TOK3;
            b->method = RAW;
            free(b->data);
    @@ -2417,7 +2417,7 @@ static char *cram_compress_by_method(cra
            int lev = level;
            if (method == NAME_TOK3 && lev > 3)
                lev = 3;
    -       uint8_t *cp = encode_names(in, in_size, lev, strat, &out_len, NULL);
    +       uint8_t *cp = tok3_encode_names(in, in_size, lev, strat, &out_len, 
NULL);
            *out_size = out_len;
            return (char *)cp;
        }

Reply via email to