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.
Description
When
nabc-linesis 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_statecan wrap back to 0 mid-syllable. A standaloneNABC_CUTat state 0 then creates an emptyGRE_ELEMENTwithfirst_glyph == NULL.Later,
write_default_end_of_element()ingregoriotex-write.cdereferenceselement->u.first_glyph->nextwithout 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. Withnabc-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:
The erroneous notation (extra
|beforegf) triggers the crash:Minimal reproducer
Running
gregorioon 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.