diff --git a/image/go.mod b/image/go.mod index 8817a1874c..b36373d34e 100644 --- a/image/go.mod +++ b/image/go.mod @@ -21,7 +21,7 @@ require ( github.com/klauspost/compress v1.18.6 github.com/klauspost/pgzip v1.2.6 github.com/manifoldco/promptui v0.9.0 - github.com/mattn/go-sqlite3 v1.14.45 + github.com/mattn/go-sqlite3 v1.14.47 github.com/moby/moby/api v1.54.2 github.com/moby/moby/client v0.4.1 github.com/opencontainers/go-digest v1.0.0 diff --git a/image/go.sum b/image/go.sum index afd1f13689..dc2031d9d0 100644 --- a/image/go.sum +++ b/image/go.sum @@ -112,8 +112,8 @@ github.com/mattn/go-isatty v0.0.20 h1:xfD0iDuEKnDkl03q4limB+vH+GxLEtL/jb4xVJSWWE github.com/mattn/go-isatty v0.0.20/go.mod h1:W+V8PltTTMOvKvAeJH7IuucS94S2C6jfK/D7dTCTo3Y= github.com/mattn/go-runewidth v0.0.23 h1:7ykA0T0jkPpzSvMS5i9uoNn2Xy3R383f9HDx3RybWcw= github.com/mattn/go-runewidth v0.0.23/go.mod h1:XBkDxAl56ILZc9knddidhrOlY5R/pDhgLpndooCuJAs= -github.com/mattn/go-sqlite3 v1.14.45 h1:6KA/spDguL3KV8rnybG7ezSaE4SeMR3KC9VbUoAQaIk= -github.com/mattn/go-sqlite3 v1.14.45/go.mod h1:pjEuOr8IwzLJP2MfGeTb0A35jauH+C2kbHKBr7yXKVQ= +github.com/mattn/go-sqlite3 v1.14.47 h1:jOBI62gS7nKeZv+as1oGEy0+1qISgXwH/QBlR6KbfIo= +github.com/mattn/go-sqlite3 v1.14.47/go.mod h1:6JTjA44L93a0QCyJef5YvlPoKXntQPjzWv5gtm9sB6w= github.com/miekg/pkcs11 v1.1.2 h1:/VxmeAX5qU6Q3EwafypogwWbYryHFmF2RpkJmw3m4MQ= github.com/miekg/pkcs11 v1.1.2/go.mod h1:XsNlhZGX73bx86s2hdc/FuaLm2CPZJemRLMA+WTFxgs= github.com/mistifyio/go-zfs/v4 v4.0.0 h1:sU0+5dX45tdDK5xNZ3HBi95nxUc48FS92qbIZEvpAg4= diff --git a/vendor/github.com/mattn/go-sqlite3/README.md b/vendor/github.com/mattn/go-sqlite3/README.md index fd2ef5524d..4fd391118e 100644 --- a/vendor/github.com/mattn/go-sqlite3/README.md +++ b/vendor/github.com/mattn/go-sqlite3/README.md @@ -9,8 +9,6 @@ go-sqlite3 Latest stable version is v1.14 or later, not v2. -~~**NOTE:** The increase to v2 was an accident. There were no major changes or features.~~ - # Description A sqlite3 driver that conforms to the built-in database/sql interface. diff --git a/vendor/github.com/mattn/go-sqlite3/callback.go b/vendor/github.com/mattn/go-sqlite3/callback.go index 0c518fa2c1..293d26dba0 100644 --- a/vendor/github.com/mattn/go-sqlite3/callback.go +++ b/vendor/github.com/mattn/go-sqlite3/callback.go @@ -18,7 +18,7 @@ package sqlite3 #endif #include -void _sqlite3_result_text(sqlite3_context* ctx, const char* s); +void _sqlite3_result_text(sqlite3_context* ctx, const char* s, int n); void _sqlite3_result_blob(sqlite3_context* ctx, const void* b, int l); */ import "C" @@ -29,6 +29,7 @@ import ( "math" "reflect" "sync" + "sync/atomic" "unsafe" ) @@ -104,24 +105,26 @@ type handleVal struct { } var handleLock sync.Mutex -var handleVals = make(map[unsafe.Pointer]handleVal) +var handleVals atomic.Value // stores map[unsafe.Pointer]handleVal func newHandle(db *SQLiteConn, v any) unsafe.Pointer { - handleLock.Lock() - defer handleLock.Unlock() val := handleVal{db: db, val: v} var p unsafe.Pointer = C.malloc(C.size_t(1)) if p == nil { panic("can't allocate 'cgo-pointer hack index pointer': ptr == nil") } - handleVals[p] = val + + handleLock.Lock() + defer handleLock.Unlock() + + next := cloneHandleVals(len(loadHandleVals()) + 1) + next[p] = val + handleVals.Store(next) return p } func lookupHandleVal(handle unsafe.Pointer) handleVal { - handleLock.Lock() - defer handleLock.Unlock() - return handleVals[handle] + return loadHandleVals()[handle] } func lookupHandle(handle unsafe.Pointer) any { @@ -131,12 +134,34 @@ func lookupHandle(handle unsafe.Pointer) any { func deleteHandles(db *SQLiteConn) { handleLock.Lock() defer handleLock.Unlock() - for handle, val := range handleVals { + + current := loadHandleVals() + if len(current) == 0 { + return + } + + next := make(map[unsafe.Pointer]handleVal, len(current)) + for handle, val := range current { if val.db == db { - delete(handleVals, handle) C.free(handle) + continue } + next[handle] = val } + handleVals.Store(next) +} + +func loadHandleVals() map[unsafe.Pointer]handleVal { + m, _ := handleVals.Load().(map[unsafe.Pointer]handleVal) + return m +} + +func cloneHandleVals(size int) map[unsafe.Pointer]handleVal { + next := make(map[unsafe.Pointer]handleVal, size) + for handle, val := range loadHandleVals() { + next[handle] = val + } + return next } // This is only here so that tests can refer to it. @@ -204,12 +229,13 @@ func callbackArgBytes(v *C.sqlite3_value) (reflect.Value, error) { func callbackArgString(v *C.sqlite3_value) (reflect.Value, error) { switch C.sqlite3_value_type(v) { case C.SQLITE_BLOB: - l := C.sqlite3_value_bytes(v) p := (*C.char)(C.sqlite3_value_blob(v)) + l := C.sqlite3_value_bytes(v) return reflect.ValueOf(C.GoStringN(p, l)), nil case C.SQLITE_TEXT: c := (*C.char)(unsafe.Pointer(C.sqlite3_value_text(v))) - return reflect.ValueOf(C.GoString(c)), nil + l := C.sqlite3_value_bytes(v) + return reflect.ValueOf(C.GoStringN(c, l)), nil default: return reflect.Value{}, fmt.Errorf("argument must be BLOB or TEXT") } @@ -336,6 +362,10 @@ func callbackRetBlob(ctx *C.sqlite3_context, v reflect.Value) error { C.sqlite3_result_null(ctx) } else { bs := i.([]byte) + if i64 && len(bs) > math.MaxInt32 { + C.sqlite3_result_error_toobig(ctx) + return nil + } C._sqlite3_result_blob(ctx, unsafe.Pointer(&bs[0]), C.int(len(bs))) } return nil @@ -345,8 +375,13 @@ func callbackRetText(ctx *C.sqlite3_context, v reflect.Value) error { if v.Type().Kind() != reflect.String { return fmt.Errorf("cannot convert %s to TEXT", v.Type()) } - cstr := C.CString(v.Interface().(string)) - C._sqlite3_result_text(ctx, cstr) + s := v.Interface().(string) + if i64 && len(s) > math.MaxInt32 { + C.sqlite3_result_error_toobig(ctx) + return nil + } + cstr := C.CString(s) + C._sqlite3_result_text(ctx, cstr, C.int(len(s))) return nil } diff --git a/vendor/github.com/mattn/go-sqlite3/sqlite3.go b/vendor/github.com/mattn/go-sqlite3/sqlite3.go index b07bfc7c1f..656d2dc677 100644 --- a/vendor/github.com/mattn/go-sqlite3/sqlite3.go +++ b/vendor/github.com/mattn/go-sqlite3/sqlite3.go @@ -220,8 +220,8 @@ _sqlite3_prepare_v2_internal(sqlite3 *db, const char *zSql, int nBytes, sqlite3_ } #endif -void _sqlite3_result_text(sqlite3_context* ctx, const char* s) { - sqlite3_result_text(ctx, s, -1, &free); +void _sqlite3_result_text(sqlite3_context* ctx, const char* s, int n) { + sqlite3_result_text(ctx, s, n, &free); } void _sqlite3_result_blob(sqlite3_context* ctx, const void* b, int l) { @@ -476,6 +476,12 @@ type SQLiteStmt struct { cls bool // True if the statement was created by SQLiteConn.Query namedParams map[string][3]int cacheKey string + metadata *sqliteStmtMetadata +} + +type sqliteStmtMetadata struct { + cols []string + decltype []string } // SQLiteResult implements sql.Result. @@ -2069,7 +2075,9 @@ func (c *SQLiteConn) GetFilename(schemaName string) string { if schemaName == "" { schemaName = "main" } - return C.GoString(C.sqlite3_db_filename(c.db, C.CString(schemaName))) + cSchema := C.CString(schemaName) + defer C.free(unsafe.Pointer(cSchema)) + return C.GoString(C.sqlite3_db_filename(c.db, cSchema)) } // GetLimit returns the current value of a run-time limit. @@ -2475,6 +2483,36 @@ func (rc *SQLiteRows) Close() error { return nil } +func (s *SQLiteStmt) cacheMetadata() bool { + return !s.cls || s.cacheKey != "" +} + +func (s *SQLiteStmt) columnNamesLocked(n int) []string { + if s.metadata == nil { + s.metadata = &sqliteStmtMetadata{} + } + if len(s.metadata.cols) != n { + s.metadata.cols = make([]string, n) + for i := range s.metadata.cols { + s.metadata.cols[i] = C.GoString(C.sqlite3_column_name(s.s, C.int(i))) + } + } + return s.metadata.cols +} + +func (s *SQLiteStmt) declTypesLocked(n int) []string { + if s.metadata == nil { + s.metadata = &sqliteStmtMetadata{} + } + if len(s.metadata.decltype) != n { + s.metadata.decltype = make([]string, n) + for i := range s.metadata.decltype { + s.metadata.decltype[i] = strings.ToLower(C.GoString(C.sqlite3_column_decltype(s.s, C.int(i)))) + } + } + return s.metadata.decltype +} + // Columns return column names. func (rc *SQLiteRows) Columns() []string { if rc.s == nil { @@ -2483,9 +2521,13 @@ func (rc *SQLiteRows) Columns() []string { rc.s.mu.Lock() defer rc.s.mu.Unlock() if rc.s.s != nil && int(rc.nc) != len(rc.cols) { - rc.cols = make([]string, rc.nc) - for i := range rc.cols { - rc.cols[i] = C.GoString(C.sqlite3_column_name(rc.s.s, C.int(i))) + if rc.s.cacheMetadata() { + rc.cols = rc.s.columnNamesLocked(int(rc.nc)) + } else { + rc.cols = make([]string, rc.nc) + for i := range rc.cols { + rc.cols[i] = C.GoString(C.sqlite3_column_name(rc.s.s, C.int(i))) + } } } return rc.cols @@ -2493,9 +2535,13 @@ func (rc *SQLiteRows) Columns() []string { func (rc *SQLiteRows) declTypes() []string { if rc.s.s != nil && rc.decltype == nil { - rc.decltype = make([]string, rc.nc) - for i := range rc.decltype { - rc.decltype[i] = strings.ToLower(C.GoString(C.sqlite3_column_decltype(rc.s.s, C.int(i)))) + if rc.s.cacheMetadata() { + rc.decltype = rc.s.declTypesLocked(int(rc.nc)) + } else { + rc.decltype = make([]string, rc.nc) + for i := range rc.decltype { + rc.decltype[i] = strings.ToLower(C.GoString(C.sqlite3_column_decltype(rc.s.s, C.int(i)))) + } } } return rc.decltype diff --git a/vendor/modules.txt b/vendor/modules.txt index 16bc64fd26..c19a625611 100644 --- a/vendor/modules.txt +++ b/vendor/modules.txt @@ -242,6 +242,8 @@ github.com/mattn/go-runewidth github.com/mattn/go-shellwords # github.com/mattn/go-sqlite3 v1.14.45 ## explicit; go 1.21 +# github.com/mattn/go-sqlite3 v1.14.47 +## explicit; go 1.21 github.com/mattn/go-sqlite3 # github.com/miekg/pkcs11 v1.1.2 ## explicit; go 1.12