Skip to content

Bound the C API's error message to its buffer, and enlarge the buffer - #16

Merged
nalinigans merged 1 commit into
mainfrom
tf_errmsg_bounds
Oct 7, 2026
Merged

nalinigans merged 1 commit into
mainfrom
tf_errmsg_bounds

Conversation

@tfenne

@tfenne tfenne commented Oct 6, 2026

Copy link
Copy Markdown
Contributor

As @nalinigans pointed out on #8: every C API error copies its message into tiledb_errmsg, a 2000-byte global, with strcpy. Messages name arrays and files, whose paths can be up to TILEDB_NAME_MAX_LEN (4096) characters, so a long enough name overruns the buffer: for a missing array, a name of about 1,950 characters overruns it silently, and one of 3,000 characters crashed the process. All 77 copies now go through a new set_tiledb_errmsg(), which uses snprintf and truncates if needed, and the buffer is 8192 bytes, room for a message naming two paths of the maximum length. The copies that already used snprintf were bounded and are unchanged.

New tests check that the error for a missing array with a 4,000-character name holds the whole name, which overruns the buffer on main, and that a message longer than the buffer is truncated to fit.

Every C API error copied its message into tiledb_errmsg, a 2000-byte
global, with strcpy. Messages name arrays and files, whose paths can be
up to TILEDB_NAME_MAX_LEN (4096) characters, so a long enough name
overran the buffer: a missing array with a 3,000-character name crashed
the process. Errors are now copied with snprintf through
set_tiledb_errmsg(), truncating if needed, and the buffer is 8192 bytes,
room for a message naming two paths of the maximum length.

@nalinigans nalinigans left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@nalinigans
nalinigans merged commit aff50ce into main Oct 7, 2026
10 checks passed
@nalinigans
nalinigans deleted the tf_errmsg_bounds branch October 7, 2026 18:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants