mendex/upmendex と makeindex での空入力に対する挙動の違い

Re: mendex/upmendex と makeindex での挙動の違い

- Lemures Lemniscati の投稿
返信数: 3

こちらは Ubuntu 24.04 でのテストです.
Ubuntu で配布されているパッケージのバイナリを使用しています.
mendex では Segmentation fault,upmendex では問題なしでした.

$ grep PRETTY_NAME /etc/os-release
PRETTY_NAME="Ubuntu 24.04.2 LTS

$ uname -svrmopi; bash --version | head -1; printf '%s\n' '\indexentry{entryA}{0}' '\indexentry{entryA}{-1.1.1}' | mendex -s <( printf '%s\n' 'page_compositor "."' ); printf '%s\n' "${PIPESTATUS[@]}"
Linux 6.8.0-63-generic #66-Ubuntu SMP PREEMPT_DYNAMIC Fri Jun 13 20:25:30 UTC 2025 x86_64 x86_64 x86_64 GNU/Linux
GNU bash, version 5.2.21(1)-release (x86_64-pc-linux-gnu)
This is mendex version 3.6 [12-Jun-2022] (utf8.uptex) (TeX Live 2023).
Scanning style file /dev/fd/63....done.
Scanning input file stdin....done (2 entries accepted, 0 rejected).
2 entries accepted, 0 rejected.
Sorting index....done(0 comparisons).
Sorting pages....done(2 comparisons).
Making index file.\begin{theindex}

Segmentation fault (core dumped)
0
139

$ uname -svrmopi; bash --version | head -1; printf '%s\n' '\indexentry{entryA}{0}' '\indexentry{entryA}{-1.1.1}' | upmendex -s <( printf '%s\n' 'page_compositor "."' ); printf '%s\n' "${PIPESTATUS[@]}"
Linux 6.8.0-63-generic #66-Ubuntu SMP PREEMPT_DYNAMIC Fri Jun 13 20:25:30 UTC 2025 x86_64 x86_64 x86_64 GNU/Linux
GNU bash, version 5.2.21(1)-release (x86_64-pc-linux-gnu)
This is upmendex version 1.07 [ICU 74.2] (TeX Live 2023).
Scanning style file /dev/fd/63....done.
Scanning input file stdin....done (2 entries accepted, 0 rejected).
2 entries accepted, 0 rejected.
Sorting index....done(0 comparisons).
Sorting pages....done(2 comparisons).
Making index file.\begin{theindex}

  \item entryA, -1.1.1, 0

\end{theindex}
...done.
0 warnings, written in stderr.
Output written in stdout.
0
0

$


makeindex については,同様に Segmentation fault やソート順がおかしかったりします.

$ uname -svrmopi; bash --version | head -1; printf '%s\n' '\indexentry{entryA}{0}' '\indexentry{entryA}{1234567890123456789}' '\indexentry{entryA}{12345678901234567890}' | makeindex
Linux 6.8.0-63-generic #66-Ubuntu SMP PREEMPT_DYNAMIC Fri Jun 13 20:25:30 UTC 2025 x86_64 x86_64 x86_64 GNU/Linux
GNU bash, version 5.2.21(1)-release (x86_64-pc-linux-gnu)
This is makeindex, version 2.17 [TeX Live 2023] (kpathsea + Thai support).
Scanning input file stdin....done (3 entries accepted, 0 rejected).
Sorting entries....Segmentation fault (core dumped)

$ uname -svrmopi; bash --version | head -1; printf '%s\n' '\indexentry{entryA}{0}' '\indexentry{entryA}{12345678901234567890}' | makeindex
Linux 6.8.0-63-generic #66-Ubuntu SMP PREEMPT_DYNAMIC Fri Jun 13 20:25:30 UTC 2025 x86_64 x86_64 x86_64 GNU/Linux
GNU bash, version 5.2.21(1)-release (x86_64-pc-linux-gnu)
This is makeindex, version 2.17 [TeX Live 2023] (kpathsea + Thai support).
Scanning input file stdin....done (2 entries accepted, 0 rejected).
Sorting entries....done (2 comparisons).
Generating output file stdout...\begin{theindex}
.
  \item entryA, 12345678901234567890, 0

\end{theindex}
done (5 lines written, 0 warnings).
Output written in stdout.
Transcript written in stderr.

$

Lemures Lemniscati への返信

Re: mendex/upmendex と makeindex での挙動の違い

- Lemures Lemniscati の投稿

こちらは Raspberry Pi 5 での Debian 12 です.
Debian で配布されているパッケージのバイナリを使用しています.

mendex/upmendex ともに Segmentation fault はありませんでした.
makeindex については,同様に Segmentation fault やソート順がおかしかったりします.

$ grep PRETTY_NAME /etc/os-release
PRETTY_NAME="Debian GNU/Linux 12 (bookworm)"

$ uname -svrmopi; bash --version | head -1; printf '%s\n' '\indexentry{entryA}{0}' '\indexentry{entryA}{-1.1.1}' | mendex -s <( printf '%s\n' 'page_compositor "."' ); printf '%s\n' "${PIPESTATUS[@]}"
Linux 6.12.34+rpt-rpi-2712 #1 SMP PREEMPT Debian 1:6.12.34-1+rpt1~bookworm (2025-06-26) aarch64 unknown unknown GNU/Linux
GNU bash, version 5.2.15(1)-release (aarch64-unknown-linux-gnu)
This is mendex version 3.6 [19-Sep-2021] (utf8.uptex) (TeX Live 2022).
Scanning style file /dev/fd/63....done.
Scanning input file stdin....done (2 entries accepted, 0 rejected).
2 entries accepted, 0 rejected.
Sorting index....done(0 comparisons).
Sorting pages....done(2 comparisons).
Making index file.\begin{theindex}

  \item entryA, -1.1.1, 0

\end{theindex}
...done.
0 warnings, written in stderr.
Output written in stdout.
0
0

$ uname -svrmopi; bash --version | head -1; printf '%s\n' '\indexentry{entryA}{0}' '\indexentry{entryA}{-1.1.1}' | upmendex -s <( printf '%s\n' 'page_compositor "."' ); printf '%s\n' "${PIPESTATUS[@]}"
Linux 6.12.34+rpt-rpi-2712 #1 SMP PREEMPT Debian 1:6.12.34-1+rpt1~bookworm (2025-06-26) aarch64 unknown unknown GNU/Linux
GNU bash, version 5.2.15(1)-release (aarch64-unknown-linux-gnu)
This is upmendex version 1.00 [ICU 72.1] (TeX Live 2022).
Scanning style file /dev/fd/63....done.
Scanning input file stdin....done (2 entries accepted, 0 rejected).
2 entries accepted, 0 rejected.
Sorting index....done(0 comparisons).
Sorting pages....done(2 comparisons).
Making index file.\begin{theindex}

  \item entryA, -1.1.1, 0

\end{theindex}
...done.
0 warnings, written in stderr.
Output written in stdout.
0
0

$

$ uname -svrmopi; bash --version | head -1; printf '%s\n' '\indexentry{entryA}{0}' '\indexentry{entryA}{1234567890123456789}' '\indexentry{entryA}{12345678901234567890}' | makeindex
Linux 6.12.34+rpt-rpi-2712 #1 SMP PREEMPT Debian 1:6.12.34-1+rpt1~bookworm (2025-06-26) aarch64 unknown unknown GNU/Linux
GNU bash, version 5.2.15(1)-release (aarch64-unknown-linux-gnu)
This is makeindex, version 2.16 [TeX Live 2022] (kpathsea + Thai support).
Scanning input file stdin....done (3 entries accepted, 0 rejected).
Sorting entries....Segmentation fault

$ uname -svrmopi; bash --version | head -1; printf '%s\n' '\indexentry{entryA}{0}' '\indexentry{entryA}{12345678901234567890}' | makeindex
Linux 6.12.34+rpt-rpi-2712 #1 SMP PREEMPT Debian 1:6.12.34-1+rpt1~bookworm (2025-06-26) aarch64 unknown unknown GNU/Linux
GNU bash, version 5.2.15(1)-release (aarch64-unknown-linux-gnu)
This is makeindex, version 2.16 [TeX Live 2022] (kpathsea + Thai support).
Scanning input file stdin....done (2 entries accepted, 0 rejected).
Sorting entries....done (2 comparisons).
Generating output file stdout...\begin{theindex}
.
  \item entryA, 12345678901234567890, 0

\end{theindex}
done (5 lines written, 0 warnings).
Output written in stdout.
Transcript written in stderr.

$

Lemures Lemniscati への返信

Re: mendex/upmendex と makeindex での挙動の違い

- 和田 勇 の投稿

Table of Contents

  1. 総評
  2. 検証
    1. \indexentry データ
    2. 環境による状況
      1. 思わしくないもの
      2. 良好なもの

総評

データ収集にミスがあるかもしれませんが、現時点では、makeindex mendex upmendex がどのように作成されたかが不明ですが、ubuntu 系のうち x86 環 境で問題が生じているようです。なので少なくとも x86 系の ubuntu をはじ めとする debian 系で確認が必要かもしれません。

なお t tk さんは TL2022/dev TL2026/dev なので、想像するに、正常に動く メモリ管理ライブラリを参照するようになってる可能性があると考えています。 strace を利用すれば、利用=使用するライブラリのパス情報が得られるかと 思います。

現在、当方の ubuntu / debian 環境は、諸事情でダンボールの箱の中。ですので 同環境を所有している方、追試していただけると助かります。

追試は はやてさんが示されているような make index 用スタイルファイル test.ist やindex用データファイル test.idx を使ったものをベースに環境情 報も取得できる以下を参考にして、ターミナルに表示されたもの全てをコピペ でファイルに書き込んだものをアップしていただけると情報収集が楽になりま す。

  1. test.ist (make index 用スタイルファイル)作成

    page_compositor "."
    
  2. test.idx (index用データファイル)作成

    \indexentry{entryA}{0}
    \indexentry{entryA}{-1.1.1}
    
  3. 検証用コマンドライン(テスト環境調査コマンドも含む)

    uname -a
    which -a makeindex mendex upmendex
    makeindex -s test.ist < test.idx
    mendex    -s test.ist < test.idx
    upmendex  -s test.ist < test.idx
    

検証

\indexentry データ

\indexentry{entryA}{0}
\indexentry{entryA}{-1.1.1}

環境による状況

思わしくないもの
  1. CYGWIN_NT-10.0-26100 / GNU bash, version 5.2.21(1)-release

    makeindex 2.17 エラーにはならないけど以下の警告で「-1.1.1」は無視
      !! Input index error (file = stdin, line = 2):
      – Illegal page number -1.1.1 or page_precedence rnaRA.
    mendex 3.8 「Making index file.」の処理中にSegmentation fault
    upmendex 1.11 「Making index file.」の処理中にSegmentation fault
  2. Ubuntu 24.04 / GNU bash, version 5.2.21(1)-release

    makeindex 2.17 情報なし
    mendex 3.6 「Making index file.」の処理中にSegmentation fault
    upmendex 1.07 OK
  3. Ubuntu 22.04.5 LTS on WSL の TeX Live 2024

    mendex 3.6 (TL2024) 「Making index file.」の処理中にSegmentation fault

良好なもの
  1. Ubuntu 22.04.2 LTS on WSL / bash

    makeindex 2.15 (TL2022/dev) OK
    mendex 3.5 (TL2022/dev) OK
    upmendex 0.57 (TL2022/dev) OK
    mendex 3.8 (TL2026/dev) OK
    upmendex 1.20 (TL2026/dev) OK
  2. Debian 12 on Raspberry Pi 5(aarch64) / bash 5.2.15

    mendex 3.6 (TL2022) OK
    upmendex 1.00 (TL2022) OK
  3. macOS / bash 3.2.57(1)-release / 5.3.0(1)-release

    makeindex 2.17 (TL2025) OK
    mendex 3.8 (TL2025) OK
    upmendex 1.11 (TL2025) OK
和田 勇 への返信

Re: mendex/upmendex と makeindex での挙動の違い

- Lemures Lemniscati の投稿

Cygwin でためしてみましたが,
Segmentation fault は,未初期化領域のデータにアクセスして使用した結果によるものです.

データは

test.idx 

\indexentry{entryA}{0}
\indexentry{entryA}{-1.1.1}

test.ist 

page_compositor "."

添付のファイルで

gdb < test.gdb_mendex.txt
gdb < test.gdb_upmendex.txt

を実行すると,以下のログファイル
test.gdb_mendex.log
test.gdb_upmendex.log
が生成されます.

いずれも pnumconv2() の return pnumconv(p->page+k,p->attr[cc]); における p->attr[cc] で未初期化領域のデータにアクセスしており,
そこで得られた未初期化値が pnumconv()attr に割り当てられ,page_precedence[attr] にて Segmentation fault に至ります.


pnumconv2() では,cc==2 のときに p->attr[cc] で未初期化領域を参照しますが,

これは fread.c にある chkpageattr()"-1.1.1" を扱う際に,最初の文字が '-' であるため,cc==0 のときに,次の if 文の条件がみたされることによります.

                        if (!((*page0>='0' && *page0<='9') || (*page0>='A' && *page0<='Z') || (*page0>='a' && *page0<='z'))) {
                                p->attr[cc]= -1;
                                if (cc<2) p->attr[++cc]= -1;
                                return;
                        }
この場合は,cc==0 なので,p->attr[0]=-1;  p->attr[1]=-1; と初期化されますが,p->attr[2] 以降は初期化せずに return; してしまうわけです.

以上で,今回の Segmentation fault の原因が判明しました.

しかし,ここにでてくる (cc<2) という条件が何なのかは,私には理解できていません.