AKGL_TILEMAP_MAX_TILES_PER_IMAGE is checked nowhere, and costs 512 KiB per tileset #49

Open
opened 2026-08-02 18:33:35 -04:00 by tachikoma · 0 comments
Collaborator

Source: TODO.md, "Found while writing the manual" -> "Defects with no prior entry", item 14 (at bbb7b8f)

AKGL_TILEMAP_MAX_TILES_PER_IMAGE (65,536, include/akgl/tilemap.h:52) sizes
tile_offsets[65536][2] on every tileset -- 512 KiB apiece -- and is
compared against nothing.

akgl_tilemap_compute_tileset_offsets writes one entry per tile in the image, so
a tileset declaring more tiles than the bound allows overruns the table with no
diagnostic. Every other array load in the loader was bounded in 0.5.0; this one
was missed because it is a compile-time ceiling rather than a JSON array length.

Two halves, and the first is a defect on its own:

  1. Bound the write against the macro, the shape akgl_tilemap_load_layers
    already uses.
  2. Size the table by tilecount instead of by the maximum -- which is the
    footprint refactor, filed separately, and is where the 512 KiB goes back.

Files: include/akgl/tilemap.h:52,125, src/tilemap.c:179-231


Filed by Tachikoma (Claude Code, Opus 5, 1M context)

**Source:** TODO.md, "Found while writing the manual" -> "Defects with no prior entry", item 14 (at bbb7b8f) `AKGL_TILEMAP_MAX_TILES_PER_IMAGE` (65,536, `include/akgl/tilemap.h:52`) sizes `tile_offsets[65536][2]` on every tileset -- **512 KiB apiece** -- and is **compared against nothing.** `akgl_tilemap_compute_tileset_offsets` writes one entry per tile in the image, so a tileset declaring more tiles than the bound allows overruns the table with no diagnostic. Every other array load in the loader was bounded in 0.5.0; this one was missed because it is a compile-time ceiling rather than a JSON array length. Two halves, and the first is a defect on its own: 1. **Bound the write** against the macro, the shape `akgl_tilemap_load_layers` already uses. 2. Size the table by `tilecount` instead of by the maximum -- which is the footprint refactor, filed separately, and is where the 512 KiB goes back. **Files:** `include/akgl/tilemap.h:52,125`, `src/tilemap.c:179-231` --- Filed by Tachikoma (Claude Code, Opus 5, 1M context)
tachikoma added this to the 0.9.x milestone 2026-08-02 18:33:35 -04:00
tachikoma added the defectperformanceblast-radius:medium labels 2026-08-02 18:33:35 -04:00
tachikoma added the status::grooming label 2026-08-02 18:49:22 -04:00
Sign in to join this conversation.