Skip to content

fix: memory corruption due to accessing out of bounds output vector index#39

Closed
adsharma wants to merge 1 commit into
mainfrom
fix_outvector_indexing
Closed

fix: memory corruption due to accessing out of bounds output vector index#39
adsharma wants to merge 1 commit into
mainfrom
fix_outvector_indexing

Conversation

@adsharma

@adsharma adsharma commented Jul 9, 2026

Copy link
Copy Markdown
Contributor

Fixes: LadybugDB/ladybug#672

In numpy_scan.cpp, the OBJECT/STRING scan path uses pos = i +
offset (the absolute row index in the source array) as the output
vector index for setNull() when handling None or NaN values:

  // BEFORE (buggy):
  outputVector->setNull(pos, true /* isNull */);  // pos = i + offset

The output vector is sized for DEFAULT_VECTOR_CAPACITY (= 2048)
entries and expects 0-based indices within each batch. But pos is
the absolute dataframe row index. When the COPY spans multiple
batches (i.e., when offset >= DEFAULT_VECTOR_CAPACITY), pos exceeds
the null mask buffer, causing a heap buffer overrun → the segfault
/ free(): invalid next size / munmap_chunk(): invalid pointer
crashes seen on Linux.

…ndex

 In numpy_scan.cpp, the OBJECT/STRING scan path uses pos = i +
 offset (the absolute row index in the source array) as the output
 vector index for setNull() when handling None or NaN values:

 ```cpp
   // BEFORE (buggy):
   outputVector->setNull(pos, true /* isNull */);  // pos = i + offset
 ```

 The output vector is sized for DEFAULT_VECTOR_CAPACITY (= 2048)
 entries and expects 0-based indices within each batch. But pos is
 the absolute dataframe row index. When the COPY spans multiple
 batches (i.e., when offset >= DEFAULT_VECTOR_CAPACITY), pos exceeds
 the null mask buffer, causing a heap buffer overrun → the segfault
 / free(): invalid next size / munmap_chunk(): invalid pointer
 crashes seen on Linux.
@adsharma

adsharma commented Jul 9, 2026

Copy link
Copy Markdown
Contributor Author

Folded into #38

@adsharma adsharma closed this Jul 9, 2026
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.

Bug: COPY FROM <pandas DataFrame> segfaults / aborts with heap corruption when a nullable STRING column has >2113 nulls in one call

1 participant