]> Cypherpunks repositories - gostls13.git/commit
database/sql: avoid clobbering driver-owned memory in RawBytes
authorDamien Neil <dneil@google.com>
Tue, 23 Jan 2024 23:59:47 +0000 (15:59 -0800)
committerDamien Neil <dneil@google.com>
Wed, 10 Apr 2024 20:23:22 +0000 (20:23 +0000)
commitc23579f031ecd09bf37c644723b33736dffa8b92
tree9558bc5995b581328813f9f490c7d42124248508
parent5b5d6f87a8a19848b367a0e0d8e56c0141c02193
database/sql: avoid clobbering driver-owned memory in RawBytes

Depending on the query, a RawBytes can contain memory owned by the
driver or by database/sql:

If the driver provides the column as a []byte,
RawBytes aliases that []byte.

If the driver provides the column as any other type,
RawBytes contains memory allocated by database/sql.
Prior to this CL, Rows.Scan will reuse existing capacity in a
RawBytes to permit a single allocation to be reused across rows.

When a RawBytes is reused across queries, this can result
in database/sql writing to driver-owned memory.

Add a buffer to Rows to store RawBytes data, and reuse this
buffer across calls to Rows.Scan.

Fixes #65201

Change-Id: Iac640174c7afa97eeb39496f47dec202501b2483
Reviewed-on: https://go-review.googlesource.com/c/go/+/557917
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
Reviewed-by: Roland Shoemaker <roland@golang.org>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
src/database/sql/convert.go
src/database/sql/convert_test.go
src/database/sql/sql.go
src/database/sql/sql_test.go