Skip to content

fix(ffitemplate): clone input slices where necessary#171

Open
lidavidm wants to merge 5 commits into
mainfrom
ffitemplate
Open

fix(ffitemplate): clone input slices where necessary#171
lidavidm wants to merge 5 commits into
mainfrom
ffitemplate

Conversation

@lidavidm
Copy link
Copy Markdown
Contributor

@lidavidm lidavidm commented Jun 5, 2026

No description provided.

Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR updates the Go FFI driver template to avoid aliasing caller-owned C memory by cloning input slices before passing them into driver APIs, improving safety when the C side may reuse or free buffers after calls return.

Changes:

  • Added slices usage and cloned byte slice inputs in several exported entrypoints (options, partition reads, Substrait plan, GetInfo codes).
  • Added/expanded “SAFETY” notes around fromCArr call sites to clarify when slices are used for writing vs. reading.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread ffitemplate/_tmpl/driver.go.tmpl Outdated
Comment thread ffitemplate/_tmpl/driver.go.tmpl Outdated
Comment thread ffitemplate/_tmpl/driver.go.tmpl Outdated
Comment thread ffitemplate/_tmpl/driver.go.tmpl Outdated
Comment thread ffitemplate/_tmpl/driver.go.tmpl Outdated
Comment thread ffitemplate/_tmpl/driver.go.tmpl Outdated
Comment thread ffitemplate/_tmpl/driver.go.tmpl Outdated
Comment thread ffitemplate/_tmpl/driver.go.tmpl Outdated
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 1 out of 1 changed files in this pull request and generated 3 comments.

Comment thread ffitemplate/_tmpl/driver.go.tmpl
Comment thread ffitemplate/_tmpl/driver.go.tmpl Outdated
Comment thread ffitemplate/_tmpl/driver.go.tmpl Outdated
@lidavidm lidavidm marked this pull request as ready for review June 5, 2026 07:14
@lidavidm lidavidm requested a review from amoeba June 5, 2026 07:14
cdb := getFromHandle[cDatabase](db.private_data)
k := C.GoString(key)
v := fromCArr[byte](value, int(length))
var safeLen int
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Why not just use c.GoBytes(value, length)?

That would do the checks and create the copy, outputting a []byte for you and simplify this a bit.

if safeLen, code = checkLengthToInt(length, err); code != C.ADBC_STATUS_OK {
return code
}
e := conn.cnxn.SetOptionBytes(conn.newContext(), C.GoString(key), slices.Clone(fromCArr[byte](value, safeLen)))
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Same comment as above, just use c.GoBytes instead of slices.Clone(fromCArr....)

if safeLen, code = checkLengthToInt(length, err); code != C.ADBC_STATUS_OK {
return code
}
e := st.stmt.SetSubstraitPlan(st.newContext(), slices.Clone(fromCArr[byte](plan, safeLen)))
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

And so on.... Not gonna comment at every call site

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.

3 participants