Gentoo Websites Logo
Go to: Gentoo Home Documentation Forums Lists Bugs Planet Store Wiki Get Gentoo!
Bug 930039 - dev-libs/tree-sitter-0.22.4: breaks ABI, causes dev-util/pkgcheck hangs/crashes
Summary: dev-libs/tree-sitter-0.22.4: breaks ABI, causes dev-util/pkgcheck hangs/crashes
Status: RESOLVED FIXED
Alias: None
Product: Gentoo Linux
Classification: Unclassified
Component: Current packages (show other bugs)
Hardware: All Linux
: Normal normal
Assignee: Ali Abdel-Qader
URL:
Whiteboard:
Keywords: PullRequest
Depends on:
Blocks:
 
Reported: 2024-04-15 02:20 UTC by Sam James
Modified: 2024-04-19 07:26 UTC (History)
7 users (show)

See Also:
Package list:
Runtime testing required: ---


Attachments
Large backtrace from pytest on pkgcheck (file_930039.txt,138.67 KB, text/plain)
2024-04-15 02:38 UTC, Sam James
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Sam James archtester Gentoo Infrastructure gentoo-dev Security 2024-04-15 02:20:34 UTC
With dev-libs/tree-sitter-0.22.4, `pkgcheck scan` seems to crash (sometimes) in app-shells/bash, and hangs in sys-devel/gcc. The behaviour is inconsistent though.

After rebuilding the following with debug symbols to poke more, the issue went away, which means it's likely an ABI break:
```
dev-libs/tree-sitter
dev-libs/tree-sitter-bash
dev-libs/tree-sitter-c
dev-libs/tree-sitter-cpp
dev-libs/tree-sitter-python
dev-python/tree-sitter
dev-util/tree-sitter-cli
```

libabigail's abidiff output is:
```
$ abidiff /var/tmp/portage/dev-libs/tree-sitter-0.22.{2,4}/image/usr/lib64/libtree-sitter.so.0.22 --fail-no-debug-info --debug-info-dir1 /var/tmp/portage/dev-libs/tree-sitter-0.22.2/image/usr/lib/debug --debug-info-dir2 /var/tmp/portage/dev-libs/tree-sitter-0.22.4/image/usr/lib/debug
Functions changes summary: 0 Removed, 4 Changed (45 filtered out), 0 Added functions
Variables changes summary: 0 Removed, 0 Changed, 0 Added variable

4 functions with some indirect sub-type change:

  [C] 'function const size_t* ts_parser_cancellation_flag(const TSParser*)' at parser.c:1921:1 has some indirect sub-type changes:
    parameter 1 of type 'const TSParser*' has sub-type changes:
      in pointed to type 'const TSParser':
        in unqualified underlying type 'typedef TSParser' at api.h:45:1:
          underlying type 'struct TSParser' at parser.c:90:1 changed:
            type size hasn't changed
            1 data member insertion:
              'bool has_scanner_error', at offset 11616 (in bits) at parser.c:113:1

  [C] 'function void ts_query_cursor_delete(TSQueryCursor*)' at query.c:2986:1 has some indirect sub-type changes:
    parameter 1 of type 'TSQueryCursor*' has sub-type changes:
      in pointed to type 'typedef TSQueryCursor' at api.h:48:1:
        underlying type 'struct TSQueryCursor' at query.c:301:1 changed:
          type size changed from 1152 to 1216 (in bits)
          15 data member changes:
            type of 'TSTreeCursor cursor' changed:
              underlying type 'struct TSTreeCursor' at api.h:105:1 changed:
                type size changed from 192 to 256 (in bits)
                1 data member change:
                  type of 'uint32_t context[2]' changed:
                    type name changed from 'uint32_t[2]' to 'uint32_t[3]'
                    array type size changed from 64 to 96
                    array type subrange 1 changed length from 2 to 3
            'struct {QueryState* contents; uint32_t size; uint32_t capacity;} states' offset changed from 256 to 320 (in bits) (by +64 bits)
            'struct {QueryState* contents; uint32_t size; uint32_t capacity;} finished_states' offset changed from 384 to 448 (in bits) (by +64 bits)
            'CaptureListPool capture_list_pool' offset changed from 512 to 576 (in bits) (by +64 bits)
            'uint32_t depth' offset changed from 832 to 896 (in bits) (by +64 bits)
            'uint32_t max_start_depth' offset changed from 864 to 928 (in bits) (by +64 bits)
            'uint32_t start_byte' offset changed from 896 to 960 (in bits) (by +64 bits)
            'uint32_t end_byte' offset changed from 928 to 992 (in bits) (by +64 bits)
            'TSPoint start_point' offset changed from 960 to 1024 (in bits) (by +64 bits)
            'TSPoint end_point' offset changed from 1024 to 1088 (in bits) (by +64 bits)
            'uint32_t next_state_id' offset changed from 1088 to 1152 (in bits) (by +64 bits)
            'bool on_visible_node' offset changed from 1120 to 1184 (in bits) (by +64 bits)
            'bool ascending' offset changed from 1128 to 1192 (in bits) (by +64 bits)
            'bool halted' offset changed from 1136 to 1200 (in bits) (by +64 bits)
            'bool did_exceed_match_limit' offset changed from 1144 to 1208 (in bits) (by +64 bits)

  [C] 'function TSTreeCursor ts_tree_cursor_copy(const TSTreeCursor*)' at tree_cursor.c:695:1 has some indirect sub-type changes:

  [C] 'function TSTreeCursor ts_tree_cursor_new(TSNode)' at tree_cursor.c:153:1 has some indirect sub-type changes:
```

I've filed a bug upstream with libabigail after discussion on IRC wrt why it didn't flag it as a breaking change (https://sourceware.org/bugzilla/show_bug.cgi?id=31642).
Comment 1 Sam James archtester Gentoo Infrastructure gentoo-dev Security 2024-04-15 02:21:19 UTC
A good reproducer for me before I rebuilt was pkgcheck's test suite. I started debugging with `gdb --args python3.10 -m pytest 'tests/checks/test_codingstyle.py::TestStaticSrcUri::test_no_report[${P}]'`.
Comment 2 Sam James archtester Gentoo Infrastructure gentoo-dev Security 2024-04-15 02:38:25 UTC
Created attachment 890852 [details]
Large backtrace from pytest on pkgcheck
Comment 3 Sam James archtester Gentoo Infrastructure gentoo-dev Security 2024-04-15 02:40:25 UTC
(In reply to Sam James from comment #2)
> Created attachment 890852 [details]
> Large backtrace from pytest on pkgcheck

And Valgrind:
```
tests/checks/test_codingstyle.py::TestStaticSrcUri::test_no_report[${P}] ==602430== Invalid write of size 8
==602430==    at 0xDC597D4: ts_query_cursor_set_byte_range (query.c:3064)
==602430==    by 0xD609CA2: query_captures (binding.c:2110)
==602430==    by 0x49A2602: method_vectorcall_VARARGS_KEYWORDS (descrobject.c:344)
==602430==    by 0x498E16D: UnknownInlinedFun (abstract.h:114)
==602430==    by 0x498E16D: UnknownInlinedFun (abstract.h:123)
==602430==    by 0x498E16D: UnknownInlinedFun (ceval.c:5893)
==602430==    by 0x498E16D: _PyEval_EvalFrameDefault (ceval.c:4198)
==602430==    by 0x49D4AE9: UnknownInlinedFun (pycore_ceval.h:46)
==602430==    by 0x49D4AE9: UnknownInlinedFun (genobject.c:213)
==602430==    by 0x49D4AE9: gen_iternext (genobject.c:580)
==602430==    by 0x498E39F: _PyEval_EvalFrameDefault (ceval.c:4001)
==602430==    by 0x49D4E02: UnknownInlinedFun (pycore_ceval.h:46)
==602430==    by 0x49D4E02: gen_send_ex2 (genobject.c:213)
==602430==    by 0x4990580: _PyEval_EvalFrameDefault (ceval.c:2586)
==602430==    by 0x49D4AE9: UnknownInlinedFun (pycore_ceval.h:46)
==602430==    by 0x49D4AE9: UnknownInlinedFun (genobject.c:213)
==602430==    by 0x49D4AE9: gen_iternext (genobject.c:580)
==602430==    by 0x49DCFC4: list_extend (listobject.c:960)
==602430==    by 0x49AC14C: method_vectorcall_O (descrobject.c:460)
==602430==    by 0x498E16D: UnknownInlinedFun (abstract.h:114)
==602430==    by 0x498E16D: UnknownInlinedFun (abstract.h:123)
==602430==    by 0x498E16D: UnknownInlinedFun (ceval.c:5893)
==602430==    by 0x498E16D: _PyEval_EvalFrameDefault (ceval.c:4198)
==602430==  Address 0xa430078 is 24 bytes after a block of size 944 in arena "client"
==602430==

valgrind: m_mallocfree.c:304 (get_bszB_as_is): Assertion 'bszB_lo == bszB_hi' failed.
valgrind: Heap block lo/hi size mismatch: lo = 1008, hi = 18446744069414584320.
This is probably caused by your program erroneously writing past the
end of a heap block and corrupting heap metadata.  If you fix any
invalid writes reported by Memcheck, this assertion failure will
probably go away.  Please try that before reporting this as a bug.
```
Comment 4 Larry the Git Cow gentoo-dev 2024-04-15 07:25:49 UTC
The bug has been referenced in the following commit(s):

https://gitweb.gentoo.org/repo/gentoo.git/commit/?id=fd7ecadcca4dd220302c3f7dadddee91c251d929

commit fd7ecadcca4dd220302c3f7dadddee91c251d929
Author:     Matthew Smith <matthew@gentoo.org>
AuthorDate: 2024-04-15 07:05:51 +0000
Commit:     Matthew Smith <matthew@gentoo.org>
CommitDate: 2024-04-15 07:25:19 +0000

    dev-libs/tree-sitter: add subslot
    
    The ABI break seemed to be unintentional, but adding a subslot will be
    useful in the future as a break with version 1.0 of tree-sitter looks
    to be planned.
    
    Ref: https://github.com/tree-sitter/tree-sitter/issues/930#issuecomment-782924093
    Bug: https://bugs.gentoo.org/930039
    Signed-off-by: Matthew Smith <matthew@gentoo.org>

 dev-libs/tree-sitter/tree-sitter-0.22.4-r1.ebuild | 49 +++++++++++++++++++++++
 1 file changed, 49 insertions(+)

https://gitweb.gentoo.org/repo/gentoo.git/commit/?id=474595aa6cbdf74f4489378f87f83534b4c3d926

commit 474595aa6cbdf74f4489378f87f83534b4c3d926
Author:     Matthew Smith <matthew@gentoo.org>
AuthorDate: 2024-04-15 07:03:45 +0000
Commit:     Matthew Smith <matthew@gentoo.org>
CommitDate: 2024-04-15 07:25:19 +0000

    profiles: mask dev-libs/tree-sitter-0.22.4
    
    Bug: https://bugs.gentoo.org/930039
    Signed-off-by: Matthew Smith <matthew@gentoo.org>

 profiles/package.mask | 4 ++++
 1 file changed, 4 insertions(+)
Comment 5 Sam James archtester Gentoo Infrastructure gentoo-dev Security 2024-04-16 02:47:44 UTC
I think we're done for our side here.
Comment 6 Sam James archtester Gentoo Infrastructure gentoo-dev Security 2024-04-19 05:04:21 UTC
According to https://github.com/tree-sitter/tree-sitter/pull/3302#issuecomment-2061838409, we should do 0/${PV} going forward.
Comment 7 Larry the Git Cow gentoo-dev 2024-04-19 07:26:34 UTC
The bug has been referenced in the following commit(s):

https://gitweb.gentoo.org/repo/gentoo.git/commit/?id=00bd822f4fd40f12ccaf16f2af83d39595484ce9

commit 00bd822f4fd40f12ccaf16f2af83d39595484ce9
Author:     Matthew Smith <matthew@gentoo.org>
AuthorDate: 2024-04-19 07:24:10 +0000
Commit:     Matthew Smith <matthew@gentoo.org>
CommitDate: 2024-04-19 07:25:39 +0000

    dev-libs/tree-sitter: add 0.22.5
    
    Set subslot to ${PV} to handle unstable ABI.
    
    Bug: https://bugs.gentoo.org/930039
    Signed-off-by: Matthew Smith <matthew@gentoo.org>

 dev-libs/tree-sitter/Manifest                  |  1 +
 dev-libs/tree-sitter/tree-sitter-0.22.5.ebuild | 50 ++++++++++++++++++++++++++
 2 files changed, 51 insertions(+)