Skip to content

bug: dstr_insert_ch writes one byte past the buffer when inserting mid-string #46

Closed

Description

@zackees

libobs/util/dstr.c dstr_insert_ch calls dstr_ensure_capacity(dst, ++dst->len + 1) and then memmove(dst->array + idx + 1, dst->array + idx, dst->len - idx + 1). Because it uses the already incremented len, it moves one byte too many and writes array[new_len + 1]. That is out of bounds when capacity == new_len + 1 (e.g. "ac" with capacity 4, then insert_ch(1, 'b')).

Found by the Phase 3 reviewer. test_dstr.c currently avoids the case rather than characterizing it. Fix in C (RED: an ASan cmocka test for exactly that case), and the dstr port (#43) must not reproduce it.

Refs #4, #43

Activity

  1. added 6 commits that reference this issue on Oct 10, 2026
    15a28c0
    df3d37a
    b67ffe0
    44b8ca5
    d78753f
    b90c14a
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions