Fixed out of bounds fix after drop column.#3134
Conversation
|
Claude finished @khustup2's task in 6m 29s —— View job PR Review: Fixed out of bounds fix after drop columnI've reviewed the changes in this PR. The fix correctly addresses the out-of-bounds access issue when columns are dropped by properly mapping between logical column indices and TupleDesc indices. SummaryChanges look correct overall. The PR:
Architecture UnderstandingThe code maintains three index spaces:
The mappings:
Minor Observations
No significant issues found. The changes appear to correctly fix the out-of-bounds access issue that would occur when columns are dropped. |
|
| { | ||
| for (auto col : null_columns_) { | ||
| nulls[col] = true; | ||
| const auto slot_pos = table_data_.get_tupdesc_index(col); |
There was a problem hiding this comment.
Bug: Incorrect slot position mapping in convert_nd_to_pg
The col variable here is a logical column index (0-based, excluding dropped columns), but slot_pos is the TupleDesc index. However, the values and nulls arrays passed to this function are sized according to tupdesc->natts and should be indexed by TupleDesc position, not slot position.
Problem: When a column is dropped, TupleDesc indices don't match logical indices. For example, if column 1 is dropped in a 3-column table:
- Logical index 0 → TupleDesc index 0 (OK)
- Logical index 1 → TupleDesc index 2 (maps to physical column 2, but slot arrays expect index 1)
This causes out-of-bounds writes to values[] and nulls[] arrays when there are dropped columns, corrupting memory.
Fix: The function should directly index values[slot_pos] and nulls[slot_pos] without going through get_tupdesc_index(), since slot_pos already IS the correct TupleDesc index. The current code double-maps the index incorrectly.
| const auto slot_pos = table_data_.get_tupdesc_index(col); | |
| for (auto col : null_columns_) { | |
| nulls[col] = true; | |
| } | |
| for (auto col : scored_columns_) { | |
| nulls[col] = false; | |
| } | |
| for (auto col : special_columns_) { | |
| values[col] = pg::utils::make_special_datum(table_id_, row_number, col, table_data_.get_base_atttypid(col)); | |
| nulls[col] = false; | |
| } | |
| for (auto col : process_columns_) { | |
| auto [datum, is_null] = get_datum(col, row_number); | |
| values[col] = datum; | |
| nulls[col] = is_null; | |
| } |
Wait, I need to reconsider this...



🚀 🚀 Pull Request
Impact
Description
Things to be aware of
Things to worry about
Additional Context