#1130237 ledger convert segfaults

Package:
ledger
Source:
ledger
Description:
command-line double-entry accounting program
Submitter:
Alex
Date:
2026-03-15 02:11:01 UTC
Severity:
normal
Tags:
#1130237#5
Date:
2026-03-09 22:54:41 UTC
From:
To:
Dear Maintainer,

please find a script below to reproduce a segmentation fault when
calling ledger convert:

```
#!/bin/sh

set -e

ledger --version

cd /tmp
rm -rf ledger-segfault && mkdir ledger-segfault
cd ledger-segfault

# create three example files (1 ledger, 2 csvs to be imported):
cat << EOF > test.dat
tag CSV
tag Imported
tag reference_id
    assert value =~ /^[*]{8}[0-9]{19}/

2025/11/15 Order 12345
    Assets:Accounts Receivable              EUR 1025
    Income:Sales
EOF

cat << EOF > final1.csv
date,description,total,amount,reference_id
2025-11-29,,EUR 25.0,EUR 25.0,********6521949711467142203
EOF

cat << EOF > final2.csv
date,description,total,amount,reference_id
2026-03-03,Order 12345,EUR 100.0,EUR 100.0,********9581361030270551453
EOF

set -x

# call ledger convert for the final1.csv (SUCCESS):
ledger convert final1.csv --input-date-format "%Y-%m-%d" --invert --account "Assets:Bank One" --rich-data --file test.dat --now 2026-03-09

# append ledger convert output of final1.csv to ledger (SUCCESS):
ledger convert final1.csv --input-date-format "%Y-%m-%d" --invert --account "Assets:Bank One" --rich-data --file test.dat --now 2026-03-09 >> test.dat

# call ledger convert for the final2.csv (SEGFAULT):
ledger convert final2.csv --input-date-format "%Y-%m-%d" --invert --account "Assets:Bank One" --rich-data --file test.dat --now 2026-03-09
```

Running the script through strace gives me this:

```
[...]
wait4(-1, [{WIFEXITED(s) && WEXITSTATUS(s) == 0}], 0, NULL) = 319633
--- SIGCHLD {si_signo=SIGCHLD, si_code=CLD_EXITED, si_pid=319633, si_uid=1000, si_status=0, si_utime=0, si_stime=0} ---
rt_sigreturn({mask=[]})                 = 319633
wait4(-1, 0x7ffdd799f06c, WNOHANG, NULL) = -1 ECHILD (No child processes)
dup2(11, 1)                             = 1
close(11)                               = 0
write(2, "+ ", 2+ )                       = 2
write(2, "ledger", 6ledger)                   = 6
write(2, " convert", 8 convert)                 = 8
write(2, " final2.csv", 11 final2.csv)             = 11
write(2, " --input-date-format", 20 --input-date-format)    = 20
write(2, " %Y-%m-%d", 9 %Y-%m-%d)                = 9
write(2, " --invert", 9 --invert)                = 9
write(2, " --account", 10 --account)              = 10
write(2, " Assets:Bank One", 16 Assets:Bank One)        = 16
write(2, " --rich-data", 12 --rich-data)            = 12
write(2, " --file", 7 --file)                  = 7
write(2, " test.dat", 9 test.dat)                = 9
write(2, " --now", 6 --now)                   = 6
write(2, " 2026-03-09", 11 2026-03-09)             = 11
write(2, "\n", 1
)                       = 1
rt_sigprocmask(SIG_SETMASK, ~[RTMIN RT_1], NULL, 8) = 0
vfork()                                 = 319634
rt_sigprocmask(SIG_SETMASK, [], ~[KILL STOP RTMIN RT_1], 8) = 0
wait4(-1, [{WIFSIGNALED(s) && WTERMSIG(s) == SIGSEGV}], 0, NULL) = 319634
--- SIGCHLD {si_signo=SIGCHLD, si_code=CLD_KILLED, si_pid=319634, si_uid=1000, si_status=SIGSEGV, si_utime=0, si_stime=0} ---
rt_sigreturn({mask=[]})                 = 319634
write(2, "Segmentation fault\n", 19Segmentation fault
)    = 19
0x7ffdd799f06c, WNOHANG, NULL) = -1 ECHILD (No child processes)
exit_group(139)                         = ?
+++ exited with 139 +++
```

which doesn't tell me much.

Commenting out the regex tag assertion for reference_id in test.dat
solves the problem, so I _assume_ it has something to do with it.

Might need forwarding upstream, if the issue persists on newer versions
of upstream. I haven't tested newer upstream versions.

Thank you for looking into this and your work on the package!

#1130237#10
Date:
2026-03-12 22:05:15 UTC
From:
To:
Alex <alex@puer-robustus.eu> writes:

Weirdly, I don't see the segfault with 3.4.0-1 unless I add
--no-pager to the first ledger call. Probably this flakieness is related
to the memory error discussed at

https://github.com/ledger/ledger/issues/2883

#1130237#17
Date:
2026-03-12 22:05:15 UTC
From:
To:
Alex <alex@puer-robustus.eu> writes:

Weirdly, I don't see the segfault with 3.4.0-1 unless I add
--no-pager to the first ledger call. Probably this flakieness is related
to the memory error discussed at

https://github.com/ledger/ledger/issues/2883

#1130237#22
Date:
2026-03-15 02:08:28 UTC
From:
To:
David Bremner <david@tethera.net> writes:

Upstream claims to have fixed this via

https://github.com/ledger/ledger/pull/2885