Line offset list monotonicity assertion is only checked on the resize slow path

オープン 初心者向け
#4,347 コメント 0 件 リアクション 0 件 担当者 0 名 GitHub で見る

メンテナーはふだん 1 日以内に返信

まだ誰も着手していません。

評価

難易度
2/5
見積もり時間
1〜3時間
初心者へのやさしさ
78/100
issue の種類
バグ
明瞭さ
明確に書かれている
活発さ
活発
技術スタック
c
領域
backend

調査の方向性

include/prism/internal/line_offset_list.h と src/line_offset_list.c を読み、pm_line_offset_list_append と pm_line_offset_list_append_slow に注目してください。高速追加と低速追加の両方でアサーションがどのように動作するかを確認し、関連する行オフセットリストのテストを実行してください。デバッグビルドで、重複したオフセットまたは順序が前後したオフセットがどちらの経路でもアサーションを発生させれば完了です。

索引モデルが issue の本文から書いたものです。

説明

Prism records the byte offset of the start of each source line in parser->line_offsets (pm_line_offset_list_t), which must remain strictly monotonically increasing so that binary search (pm_line_offset_list_line and pm_line_offset_list_line_column) can map byte offsets to 1-based line and column numbers.

Currently, the monotonicity assertion

PRISM_ASSERT(list->size == 0 || cursor > list->offsets[list->size - 1]);

is placed inside pm_line_offset_list_append_slow (src/line_offset_list.c) rather than the inline fast path pm_line_offset_list_append (include/prism/internal/line_offset_list.h). As a result, any duplicate or out-of-order line offset appended while list->size < list->capacity silently succeeds even in debug builds with PRISM_ASSERT enabled.

Reproduction

In #4346, we see on 774aebc1f

$ ruby -Ilib -rprism -e 'p Prism.parse("<<\"\#{0}\n\#{<<0}\\C-\n\#{0}\n\n").source.offsets'
# => [0, 8, 18, 23, 24, 23, 24]

For my mac os prism version, I see an abort:

ruby  -rprism -e 'p Prism.parse("<<\"\#{0}\n\#{<<0}\\C-\n\#{0}\n\n").source.offsets'
# => [0, 8, 18, 23, 24, 23, 24]
Assertion failed: (list->size == 0 || newline_offset > list->offsets[list->size - 1]), function pm_newline_list_append, file pm_newline_list.c, line 51.
-e:1: [BUG] Aborted at 0x000000018d7c1650
ruby 4.0.1 (2026-01-13 revision e04267a14b) +PRISM [arm64-darwin25]

-- Crash Report log information --------------------------------------------
   See Crash Report log file in one of the following locations:
     * ~/Library/Logs/DiagnosticReports
     * /Library/Logs/DiagnosticReports
   for more details.
Don't forget to include the above Crash Report log file in bug reports.
主要言語
C
スター
1k
フォーク
202
平均マージ
6時間 18分
マージ済み PR(30日)
77

環境構築

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

ruby/prism のほかの issue

ruby/prism の issue をすべて見る

似ている issue

C の issue をもっと見る

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。