Line offset list monotonicity assertion is only checked on the resize slow path
维护者通常 1 天内回复
还没有人认领这个 Issue。
评估
调研方向
阅读 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 模板
- 阅读贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
ruby/prism 的其他 Issue
-
难度 4/5 3-5 天 新手友好度 35/100
维护者通常 1 天内回复
-
难度 3/5 1-2 天 新手友好度 55/100
维护者通常 1 天内回复
-
难度 5/5 一周以上 新手友好度 30/100
维护者通常 1 天内回复
相似的 Issue
-
good first issue help wanted program
难度 2/5 1-3 小时 新手友好度 83/100
hffgzktbcc-blip/ounce-core#297 ·
维护者通常 1 天内回复
-
难度 2/5 1-3 小时 新手友好度 65/100
-
难度 2/5 1-3 小时 新手友好度 72/100
coolsnowwolf/lede#14283 · 1 条评论 ·
-
难度 2/5 1-3 小时 新手友好度 65/100
OpenVisualCloud/SVT-JPEG-XS#130 ·
维护者通常 1 天内回复
-
难度 2/5 1-3 小时 新手友好度 68/100
维护者通常 1 天内回复