Menu

#2085 `~at` with a spread array whose leading slot is empty segfaults: `validateIndex` takes `items()` alongside `data()`

5.3.0
open
nobody
None
none
5
2026-08-22
2026-08-22
No
a = (1,2)
say a~at((,2))

exits with SIGSEGV, rc 139. Measured deterministic, three runs of three, and the same for
a~at((,,3)).

ArrayClass::validateIndex spreads a lone array argument into the subscript list by taking its item
count alongside its slot array (interpreter/classes/ArrayClass.cpp:1219-1226):
indexCount = indirect->items() and index = indirect->data(). But items() counts the non-empty
slots while data() returns the raw slot array, so an array whose leading slot is empty and which
holds exactly one item hands validateSingleDimensionIndex an indexCount of 1 with
index[0] == OREF_NULL. Line 1264 then calls index[0]->requiredPositive(argPosition) on that null.

The neighbours are all clean and identify the shape exactly. a~at((1,)) answers 1 (one item,
leading slot filled); a~at((1,,3)) raises 93.926 (two items, so the count is rejected before either
subscript is read); a~at((,)) raises 93.901 (no items at all). The crashing shape is any array whose
first filled slot is not slot one and which holds exactly one item.

Discussion

Anonymous
Anonymous

Add attachments
Cancel