Skip to content

Conversation

@0xYashwanth
Copy link
Contributor

bug causing out-of-bounds memory access in AddUpdated() when updating cached row status.

In the else if (upd_idx >= 0) branch at line 2691, the code updates res->updated_keyset[upd_idx].status but then incorrectly accesses res->added_tuples + num_fields * upd_add_idx to clear cached data.

When a row's status in the updated_keyset array is modified, the corresponding cached tuple data must be invalidated.
The invariant is: for any index i, the tuple cache entry is stored at base_array + num_fields * i. Since we're modifying updated_keyset[upd_idx], the corresponding tuple cache is at updated_tuples + num_fields * upd_idx.
Using the wrong base array (added_tuples) or wrong index (upd_add_idx = -1) violates this and produces undefined behavior.

Fix

tuple = res->updated_tuples + num_fields * upd_idx;

@davecramer
Copy link
Contributor

is there a way to test this ?

@davecramer davecramer merged commit a68befe into postgresql-interfaces:main Jan 7, 2026
1 check passed
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