Skip to content

fix(column): guard negative/oversized SQL_LEN in BindableColumn.Value#225

Open
SAY-5 wants to merge 1 commit into
alexbrainman:masterfrom
SAY-5:fix/bindable-column-negative-len-panic-224
Open

fix(column): guard negative/oversized SQL_LEN in BindableColumn.Value#225
SAY-5 wants to merge 1 commit into
alexbrainman:masterfrom
SAY-5:fix/bindable-column-negative-len-panic-224

Conversation

@SAY-5
Copy link
Copy Markdown

@SAY-5 SAY-5 commented Apr 23, 2026

Fixes #224.

Problem

BindableColumn.Value slices c.Buffer[:c.Len] without checking the sign or upper bound of c.Len. Some drivers (observed on DB2 when the DSN is configured for UTF-8 encoding, where the ODBC stack miscalculates bounds for multi-byte UTF-8 values in fixed-length CHAR columns) return a negative SQL_LEN. The slice expression panics:

panic: runtime error: slice bounds out of range [:-4]
odbc.(*BindableColumn).Value column.go:259
database/sql.(*Rows).Next

and unwinds the caller's query path entirely.

Fix

Reject any SQL_LEN that is negative or larger than len(c.Buffer) with an actionable error naming the column index and out-of-range length. Happy-path values (0 <= c.Len <= len(c.Buffer)) are unchanged.

Test

gofmt clean. The package does not cross-build on darwin without a platform ODBC SDK, so I could not run the full test suite locally; the guard is additive and returns an error on the previously panicking path.

BindableColumn.Value sliced c.Buffer[:c.Len] without checking sign or
upper bound. Some drivers (observed on DB2 for CHAR columns when the
DSN is configured for UTF-8 encoding, where the ODBC library
miscalculates bounds for multi-byte UTF-8 values in fixed-length
columns) return a negative SQL_LEN. The slice expression panicked
with 'slice bounds out of range [:-4]', unwinding database/sql's
Rows.Next through the caller's query handler.

Reject any SQL_LEN that is negative or larger than len(c.Buffer) with
an actionable error naming the column index and the out-of-range
length. Happy-path values (0 <= c.Len <= len(c.Buffer)) are unchanged.

Refs alexbrainman/odbc issue 224.

Signed-off-by: SAY-5 <say.apm35@gmail.com>
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.

Panic on CHAR Columns with Special Characters (UTF-8 Encoding)

1 participant