Skip to content

Segfault when nabc_state wraps to 0 mid-syllable creating empty GRE_ELEMENT #1726

@lbssousa

Description

@lbssousa

Description

When nabc-lines is set to 2, the NABC state cycles modulo 3 (0 = GABC notes, 1 = voice 1, 2 = voice 2). If a syllable contains a GABC syntax error with an extra | separator — e.g. || where only | was intended — nabc_state can wrap back to 0 mid-syllable. A standalone NABC_CUT at state 0 then creates an empty GRE_ELEMENT with first_glyph == NULL.

Later, write_default_end_of_element() in gregoriotex-write.c dereferences element->u.first_glyph->next without a NULL check, causing a segmentation fault.

Context

In the GABC notation for two NABC voices, a single | advances to the next NABC state while || advances by two. With nabc-lines: 2, the correct way to start a new GABC element within the same syllable after voice 2 is a single | (which wraps the state from 2 back to 0). Writing || instead is a syntax error that wraps to 0 and then immediately advances to 1, leaving an empty GABC element in between.

For example, the correct notation is:

ma(f!hhf||ta//tghh|gf||cl)

The erroneous notation (extra | before gf) triggers the crash:

ma(f!hhf||ta//tghh||gf||cl)

Minimal reproducer

name:t;
nabc-lines:2;
%%
(f3) ma(f!hhf||ta//tghh||gf||cl) (::)

Running gregorio on the above file produces a segfault (core dump).

Expected behavior

Gregorio should not crash on malformed input. It should ideally report the syntax error (unexpected state wrap) and handle the empty element gracefully.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions