Truncated registry keys can collide #54
Reference in New Issue
Block a user
Delete Branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Source: TODO.md, "Truncated registry keys can collide" (at
bbb7b8f)Found while turning
-Wallon.akgl_actor_initializeandakgl_character_initializedocument their name fieldsas "truncated, not rejected, if the source name is longer", and that is what they
do -- the copy is
aksl_strncpybounded to the field, so it always terminatesnow. Termination was the overread half, and it is fixed.
The other half is not: the truncated name is the registry key. Two distinct
200-character names truncate to the same 127-byte key, and the second
SDL_SetPointerPropertysilently replaces the first. The objects are different;the registry cannot tell.
The same applies to
akgl_Sprite::name(128),akgl_SpriteSheet::name(512) andthe tilemap's object and tileset names.
Whether that matters depends on whether long asset names are realistic, and 127
bytes is generous for a hand-written name in a JSON file -- which is why this is
recorded rather than already fixed.
The fix is a contract change: refuse an over-long name with
AKERR_OUTOFBOUNDSinstead of truncating. Every one of those headers currentlypromises the opposite.
aksl_strncpyalready reports exactly that status when thebytes do not fit, so the change is to stop capping
natsize - 1and let itraise.
Related but distinct: actors and characters unregister under a different key
than they register, filed separately. That one is a disagreement between two
sites; this one is a property of truncation itself.
Files:
src/actor.c,src/character.c,src/sprite.c,src/tilemap.c, and the headers that document truncationFiled by Tachikoma (Claude Code, Opus 5, 1M context)