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

Offen Anfängerfreundlich
#4,347 0 Kommentare 0 Reaktionen 0 zugewiesene Personen Auf GitHub ansehen

Maintainer antworten meist innerhalb von 1 Tag

Dieses Issue hat noch niemand übernommen.

Bewertung

Schwierigkeit
2/5
Geschätzter Aufwand
1-3 Stunden
Anfängerfreundlichkeit
78/100
Issue-Typ
Bug
Klarheit
Klar beschrieben
Aktivitätsstatus
Aktiv
Tech-Stack
c
Bereich
backend

Rechercherichtung

Lies include/prism/internal/line_offset_list.h und src/line_offset_list.c und konzentriere dich dabei auf pm_line_offset_list_append und pm_line_offset_list_append_slow. Prüfe, wie sich die Assertion sowohl bei schnellen als auch bei langsamen Anhängvorgängen verhält, und führe anschließend die relevanten Tests für die Line-Offset-Liste aus. Erledigt ist die Aufgabe, wenn doppelte oder nicht aufsteigend sortierte Offsets in Debug-Builds auf beiden Pfaden die Assertion auslösen.

Vom Indexierungsmodell aus dem Issue-Text verfasst.

Beschreibung

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.
Vorherrschende Sprache
C
Sterne
1k
Forks
202
Ø Merge
6 Std. 18 Min.
Gemergte PRs (30 T.)
77

Entwicklungsumgebung

Erste Schritte

  1. Lesen Sie das ganze Issue und danach den Beitragsleitfaden des Projekts.
  2. Schreiben Sie ins Issue, dass Sie es übernehmen — das erspart doppelte Arbeit.
  3. Forken Sie das Repository und arbeiten Sie in einem Branch.
  4. Öffnen Sie einen Pull Request, der die Issue-Nummer nennt.

Mehr aus ruby/prism

Alle Issues in ruby/prism

Ähnliche Issues

Weitere Issues zu C

Neue Issues direkt in Ihr Postfach

Eine kurze Übersicht über anfängerfreundliche GitHub-Issues.