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

未关闭 适合新手
#4,347 0 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

维护者通常 1 天内回复

还没有人认领这个 Issue。

评估

难度
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 分钟
30 天内合并 PR
77

环境准备

  • 没有 Dockerfile 或 Docker Compose 文件
  • 没有 Pull Request 模板
  • 阅读贡献指南

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

ruby/prism 的其他 Issue

查看 ruby/prism 的全部 Issue

相似的 Issue

更多 C Issue

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。