From d43da195cb2706d8b221bbf8addb228fc7f5d35c Mon Sep 17 00:00:00 2001 From: ANAND KUMAR JHA <36113559+anandkumarjha54321@users.noreply.github.com> Date: Wed, 26 Jun 2024 02:25:30 +0530 Subject: [PATCH 1/8] GODRIVER-3257 Update client.go (#1681) Co-authored-by: Qingyang Hu --- mongo/client.go | 4 ---- 1 file changed, 4 deletions(-) diff --git a/mongo/client.go b/mongo/client.go index 280749c7dd..4266412aab 100644 --- a/mongo/client.go +++ b/mongo/client.go @@ -209,10 +209,6 @@ func NewClient(opts ...*options.ClientOptions) (*Client, error) { clientOpt.SetMaxPoolSize(defaultMaxPoolSize) } - if err != nil { - return nil, err - } - cfg, err := topology.NewConfig(clientOpt, client.clock) if err != nil { return nil, err From b10dc345d022fc64ac4d9bc5796c830a7d8c71c5 Mon Sep 17 00:00:00 2001 From: Qingyang Hu <103950869+qingyang-hu@users.noreply.github.com> Date: Wed, 26 Jun 2024 15:10:17 -0400 Subject: [PATCH 2/8] GODRIVER-3132 Use dst buf pool for zstd encoding. (#1577) --- x/mongo/driver/compression.go | 21 +++++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) diff --git a/x/mongo/driver/compression.go b/x/mongo/driver/compression.go index d79b024b74..d9a6c68fee 100644 --- a/x/mongo/driver/compression.go +++ b/x/mongo/driver/compression.go @@ -30,7 +30,11 @@ type CompressionOpts struct { // destination writer. It panics on any errors and should only be used at // package initialization time. func mustZstdNewWriter(lvl zstd.EncoderLevel) *zstd.Encoder { - enc, err := zstd.NewWriter(nil, zstd.WithEncoderLevel(lvl)) + enc, err := zstd.NewWriter( + nil, + zstd.WithWindowSize(8<<20), // Set window size to 8MB. + zstd.WithEncoderLevel(lvl), + ) if err != nil { panic(err) } @@ -105,6 +109,13 @@ func (e *zlibEncoder) Encode(dst, src []byte) ([]byte, error) { return dst, nil } +var zstdBufPool = sync.Pool{ + New: func() interface{} { + s := make([]byte, 0) + return &s + }, +} + // CompressPayload takes a byte slice and compresses it according to the options passed func CompressPayload(in []byte, opts CompressionOpts) ([]byte, error) { switch opts.Compressor { @@ -123,7 +134,13 @@ func CompressPayload(in []byte, opts CompressionOpts) ([]byte, error) { if err != nil { return nil, err } - return encoder.EncodeAll(in, nil), nil + ptr := zstdBufPool.Get().(*[]byte) + b := encoder.EncodeAll(in, *ptr) + dst := make([]byte, len(b)) + copy(dst, b) + *ptr = b[:0] + zstdBufPool.Put(ptr) + return dst, nil default: return nil, fmt.Errorf("unknown compressor ID %v", opts.Compressor) } From ba4f865353079587bd290973f9670a38102ab8b5 Mon Sep 17 00:00:00 2001 From: Preston Vasquez Date: Wed, 26 Jun 2024 15:58:04 -0600 Subject: [PATCH 3/8] GODRIVER-3248 Update windows CI build (#1675) --- .evergreen/config.yml | 43 ++++++++++++++++++++++++++++++++++--------- 1 file changed, 34 insertions(+), 9 deletions(-) diff --git a/.evergreen/config.yml b/.evergreen/config.yml index b078af8066..6af28598f6 100644 --- a/.evergreen/config.yml +++ b/.evergreen/config.yml @@ -2014,7 +2014,7 @@ axes: - id: "windows-64-go-1-20" display_name: "Windows 64-bit" run_on: - - windows-vsCurrent-latest-small + - windows-vsCurrent-small variables: GCC_PATH: "/cygdrive/c/ProgramData/chocolatey/lib/mingw/tools/install/mingw64/bin" GO_DIST: "C:\\golang\\go1.20" @@ -2038,7 +2038,7 @@ axes: - id: "windows-64-go-1-20" display_name: "Windows 64-bit" run_on: - - windows-vsCurrent-latest-small + - windows-vsCurrent-small variables: GCC_PATH: "/cygdrive/c/ProgramData/chocolatey/lib/mingw/tools/install/mingw64/bin" GO_DIST: "C:\\golang\\go1.20" @@ -2070,7 +2070,7 @@ axes: - id: "windows-64-vsCurrent-latest-small-go-1-20" display_name: "Windows 64-bit" run_on: - - windows-vsCurrent-latest-small + - windows-vsCurrent-small variables: GCC_PATH: "/cygdrive/c/ProgramData/chocolatey/lib/mingw/tools/install/mingw64/bin" GO_DIST: "C:\\golang\\go1.20" @@ -2391,23 +2391,48 @@ buildvariants: tasks: - name: "test-docker-runner" - - matrix_name: "tests-36-with-zlib-support" + - matrix_name: "tests-rhel-36-with-zlib-support" tags: ["pullrequest"] - matrix_spec: { version: ["3.6"], os-ssl-32: ["windows-64-go-1-20", "rhel87-64-go-1-20"] } + matrix_spec: { version: ["3.6"], os-ssl-32: ["rhel87-64-go-1-20"] } display_name: "${version} ${os-ssl-32}" tasks: - name: ".test !.enterprise-auth !.snappy !.zstd" - - matrix_name: "tests-40-with-zlib-support" + - matrix_name: "tests-windows-36-with-zlib-support" + matrix_spec: { version: ["3.6"], os-ssl-32: ["windows-64-go-1-20"] } + display_name: "${version} ${os-ssl-32}" + tasks: + - name: ".test !.enterprise-auth !.snappy !.zstd" + + - matrix_name: "tests-rhel-40-with-zlib-support" tags: ["pullrequest"] - matrix_spec: { version: ["4.0"], os-ssl-40: ["windows-64-go-1-20", "rhel87-64-go-1-20"] } + matrix_spec: { version: ["4.0"], os-ssl-40: ["rhel87-64-go-1-20"] } display_name: "${version} ${os-ssl-40}" tasks: - name: ".test !.enterprise-auth !.snappy !.zstd" - - matrix_name: "tests-42-plus-zlib-zstd-support" + - matrix_name: "tests-windows-40-with-zlib-support" + matrix_spec: { version: ["4.0"], os-ssl-40: ["windows-64-go-1-20"] } + display_name: "${version} ${os-ssl-40}" + tasks: + - name: ".test !.enterprise-auth !.snappy !.zstd" + + - matrix_name: "tests-rhel-42-plus-zlib-zstd-support" + tags: ["pullrequest"] + matrix_spec: { version: ["4.2", "4.4", "5.0", "6.0", "7.0", "8.0"], os-ssl-40: ["rhel87-64-go-1-20"] } + display_name: "${version} ${os-ssl-40}" + tasks: + - name: ".test !.enterprise-auth !.snappy" + + - matrix_name: "tests-windows-42-plus-zlib-zstd-support" + matrix_spec: { version: ["4.2", "4.4", "5.0", "6.0", "7.0", "8.0"], os-ssl-40: ["windows-64-go-1-20"] } + display_name: "${version} ${os-ssl-40}" + tasks: + - name: ".test !.enterprise-auth !.snappy" + + - matrix_name: "tests-windows-80-zlib-zstd-support" tags: ["pullrequest"] - matrix_spec: { version: ["4.2", "4.4", "5.0", "6.0", "7.0", "8.0"], os-ssl-40: ["windows-64-go-1-20", "rhel87-64-go-1-20"] } + matrix_spec: { version: ["8.0"], os-ssl-40: ["windows-64-go-1-20"] } display_name: "${version} ${os-ssl-40}" tasks: - name: ".test !.enterprise-auth !.snappy" From 90146e7fb28809111bdf318f21794205b0dcf28d Mon Sep 17 00:00:00 2001 From: Matt Dale <9760375+matthewdale@users.noreply.github.com> Date: Wed, 26 Jun 2024 17:00:16 -0700 Subject: [PATCH 4/8] GODRIVER-3206 Deprecate RawValue.UnmarshalWithContext (#1687) --- bson/raw_value.go | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/bson/raw_value.go b/bson/raw_value.go index 4d1bfb3160..a8088e1e30 100644 --- a/bson/raw_value.go +++ b/bson/raw_value.go @@ -88,8 +88,12 @@ func (rv RawValue) UnmarshalWithRegistry(r *bsoncodec.Registry, val interface{}) return dec.DecodeValue(bsoncodec.DecodeContext{Registry: r}, vr, rval) } -// UnmarshalWithContext performs the same unmarshalling as Unmarshal but uses the provided DecodeContext -// instead of the one attached or the default registry. +// UnmarshalWithContext performs the same unmarshalling as Unmarshal but uses +// the provided DecodeContext instead of the one attached or the default +// registry. +// +// Deprecated: Use [RawValue.UnmarshalWithRegistry] with a custom registry to customize +// unmarshal behavior instead. func (rv RawValue) UnmarshalWithContext(dc *bsoncodec.DecodeContext, val interface{}) error { if dc == nil { return ErrNilContext From ad124427ab0ffabd0f7367dcd540feb6e171df4f Mon Sep 17 00:00:00 2001 From: Steven Silvester Date: Wed, 26 Jun 2024 19:52:30 -0500 Subject: [PATCH 5/8] GODRIVER-3192 Add SSDLC workflow (#1680) Signed-off-by: mongodb-dbx-release-bot[bot] <167856002+mongodb-dbx-release-bot[bot]@users.noreply.github.com> Co-authored-by: mongodb-dbx-release-bot[bot] <167856002+mongodb-dbx-release-bot[bot]@users.noreply.github.com> --- .github/workflows/codeql.yml | 7 --- .github/workflows/release.yml | 88 +++++++++++++++++++++++++++++++++++ 2 files changed, 88 insertions(+), 7 deletions(-) create mode 100644 .github/workflows/release.yml diff --git a/.github/workflows/codeql.yml b/.github/workflows/codeql.yml index 044e1743df..21c81a32fa 100644 --- a/.github/workflows/codeql.yml +++ b/.github/workflows/codeql.yml @@ -22,13 +22,6 @@ jobs: # required for all workflows security-events: write - # required to fetch internal or private CodeQL packs - packages: read - - # only required for workflows in private repositories - actions: read - contents: read - strategy: fail-fast: false matrix: diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml new file mode 100644 index 0000000000..0f4d446237 --- /dev/null +++ b/.github/workflows/release.yml @@ -0,0 +1,88 @@ +name: Release + +on: + workflow_dispatch: + inputs: + version: + description: "The new version to set" + required: true + prev_version: + description: "The previous tagged version" + required: true + push_changes: + description: "Push changes?" + default: true + type: boolean + +defaults: + run: + shell: bash -eux {0} + +env: + # Changes per branch + SILK_ASSET_GROUP: mongodb-go-driver-v1 + EVERGREEN_PROJECT: mongo-go-driver-v1 + +jobs: + pre-publish: + environment: release + runs-on: ubuntu-latest + permissions: + id-token: write + contents: write + outputs: + prev_version: ${{ steps.pre-publish.outputs.prev_version }} + steps: + - uses: mongodb-labs/drivers-github-tools/secure-checkout@v2 + with: + app_id: ${{ vars.APP_ID }} + private_key: ${{ secrets.APP_PRIVATE_KEY }} + - uses: mongodb-labs/drivers-github-tools/setup@v2 + with: + aws_role_arn: ${{ secrets.AWS_ROLE_ARN }} + aws_region_name: ${{ vars.AWS_REGION_NAME }} + aws_secret_id: ${{ secrets.AWS_SECRET_ID }} + artifactory_username: ${{ vars.ARTIFACTORY_USERNAME }} + - name: Pre Publish + id: pre-publish + uses: mongodb-labs/drivers-github-tools/golang/pre-publish@v2 + with: + version: ${{ inputs.version }} + push_changes: ${{ inputs.push_changes }} + + static-scan: + needs: [pre-publish] + permissions: + security-events: write + uses: ./.github/workflows/codeql.yml + with: + ref: ${{ github.ref }} + + publish: + needs: [pre-publish, static-scan] + runs-on: ubuntu-latest + environment: release + permissions: + id-token: write + contents: write + security-events: read + steps: + - uses: mongodb-labs/drivers-github-tools/secure-checkout@v2 + with: + app_id: ${{ vars.APP_ID }} + private_key: ${{ secrets.APP_PRIVATE_KEY }} + - uses: mongodb-labs/drivers-github-tools/setup@v2 + with: + aws_role_arn: ${{ secrets.AWS_ROLE_ARN }} + aws_region_name: ${{ vars.AWS_REGION_NAME }} + aws_secret_id: ${{ secrets.AWS_SECRET_ID }} + artifactory_username: ${{ vars.ARTIFACTORY_USERNAME }} + - name: Publish + uses: mongodb-labs/drivers-github-tools/golang/publish@v2 + with: + version: ${{ inputs.version }} + silk_asset_group: ${{ env.SILK_ASSET_GROUP }} + evergreen_project: ${{ env.EVERGREEN_PROJECT }} + prev_version: ${{ inputs.prev_version }} + push_changes: ${{ inputs.push_changes }} + token: ${{ env.GH_TOKEN }} From 59d071797639f35d4627eb7168350773495f8d0c Mon Sep 17 00:00:00 2001 From: Matt Dale <9760375+matthewdale@users.noreply.github.com> Date: Thu, 27 Jun 2024 08:42:42 -0700 Subject: [PATCH 6/8] GODRIVER-3227 Deprecate bson.DefaultRegistry (#1688) --- bson/registry.go | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/bson/registry.go b/bson/registry.go index b5b0f35687..d6afb2850e 100644 --- a/bson/registry.go +++ b/bson/registry.go @@ -10,15 +10,27 @@ import ( "go.mongodb.org/mongo-driver/bson/bsoncodec" ) -// DefaultRegistry is the default bsoncodec.Registry. It contains the default codecs and the -// primitive codecs. +// DefaultRegistry is the default bsoncodec.Registry. It contains the default +// codecs and the primitive codecs. +// +// Deprecated: Use [NewRegistry] to construct a new default registry. To use a +// custom registry when marshaling or unmarshaling, use the "SetRegistry" method +// on an [Encoder] or [Decoder] instead: +// +// dec, err := bson.NewDecoder(bsonrw.NewBSONDocumentReader(data)) +// if err != nil { +// panic(err) +// } +// dec.SetRegistry(reg) +// +// See [Encoder] and [Decoder] for more examples. var DefaultRegistry = NewRegistry() // NewRegistryBuilder creates a new RegistryBuilder configured with the default encoders and // decoders from the bsoncodec.DefaultValueEncoders and bsoncodec.DefaultValueDecoders types and the // PrimitiveCodecs type in this package. // -// Deprecated: Use NewRegistry instead. +// Deprecated: Use [NewRegistry] instead. func NewRegistryBuilder() *bsoncodec.RegistryBuilder { rb := bsoncodec.NewRegistryBuilder() bsoncodec.DefaultValueEncoders{}.RegisterDefaultEncoders(rb) From d3437988b50d5538d53cd04b43abd9bc5808e328 Mon Sep 17 00:00:00 2001 From: Qingyang Hu <103950869+qingyang-hu@users.noreply.github.com> Date: Thu, 27 Jun 2024 12:56:42 -0400 Subject: [PATCH 7/8] GODRIVER-3240 Code hardening. (#1684) --- bson/bsoncodec/default_value_decoders.go | 4 +-- bson/bsoncodec/uint_codec.go | 8 +++-- bson/bsonrw/extjson_wrappers.go | 4 +-- bson/bsonrw/value_reader.go | 12 +++---- cmd/testatlas/{main.go => atlas_test.go} | 18 +++++++---- etc/run-atlas-test.sh | 4 +-- internal/logger/io_sink.go | 7 ++++- mongo/options/clientoptions.go | 15 ++++++++- x/bsonx/bsoncore/bsoncore.go | 40 +++++++++++------------- 9 files changed, 67 insertions(+), 45 deletions(-) rename cmd/testatlas/{main.go => atlas_test.go} (82%) diff --git a/bson/bsoncodec/default_value_decoders.go b/bson/bsoncodec/default_value_decoders.go index 7e08aab35e..fc4a7b1dbf 100644 --- a/bson/bsoncodec/default_value_decoders.go +++ b/bson/bsoncodec/default_value_decoders.go @@ -330,7 +330,7 @@ func (DefaultValueDecoders) intDecodeType(dc DecodeContext, vr bsonrw.ValueReade case reflect.Int64: return reflect.ValueOf(i64), nil case reflect.Int: - if int64(int(i64)) != i64 { // Can we fit this inside of an int + if i64 > math.MaxInt { // Can we fit this inside of an int return emptyValue, fmt.Errorf("%d overflows int", i64) } @@ -434,7 +434,7 @@ func (dvd DefaultValueDecoders) UintDecodeValue(dc DecodeContext, vr bsonrw.Valu return fmt.Errorf("%d overflows uint64", i64) } case reflect.Uint: - if i64 < 0 || int64(uint(i64)) != i64 { // Can we fit this inside of an uint + if i64 < 0 || uint64(i64) > uint64(math.MaxUint) { // Can we fit this inside of an uint return fmt.Errorf("%d overflows uint", i64) } default: diff --git a/bson/bsoncodec/uint_codec.go b/bson/bsoncodec/uint_codec.go index 8525472769..39b07135b1 100644 --- a/bson/bsoncodec/uint_codec.go +++ b/bson/bsoncodec/uint_codec.go @@ -164,11 +164,15 @@ func (uic *UIntCodec) decodeType(dc DecodeContext, vr bsonrw.ValueReader, t refl return reflect.ValueOf(uint64(i64)), nil case reflect.Uint: - if i64 < 0 || int64(uint(i64)) != i64 { // Can we fit this inside of an uint + if i64 < 0 { + return emptyValue, fmt.Errorf("%d overflows uint", i64) + } + v := uint64(i64) + if v > math.MaxUint { // Can we fit this inside of an uint return emptyValue, fmt.Errorf("%d overflows uint", i64) } - return reflect.ValueOf(uint(i64)), nil + return reflect.ValueOf(uint(v)), nil default: return emptyValue, ValueDecoderError{ Name: "UintDecodeValue", diff --git a/bson/bsonrw/extjson_wrappers.go b/bson/bsonrw/extjson_wrappers.go index 9695704246..af6ae7b76b 100644 --- a/bson/bsonrw/extjson_wrappers.go +++ b/bson/bsonrw/extjson_wrappers.go @@ -95,9 +95,9 @@ func (ejv *extJSONValue) parseBinary() (b []byte, subType byte, err error) { return nil, 0, fmt.Errorf("$binary subType value should be string, but instead is %s", val.t) } - i, err := strconv.ParseInt(val.v.(string), 16, 64) + i, err := strconv.ParseUint(val.v.(string), 16, 8) if err != nil { - return nil, 0, fmt.Errorf("invalid $binary subType string: %s", val.v.(string)) + return nil, 0, fmt.Errorf("invalid $binary subType string: %q: %w", val.v.(string), err) } subType = byte(i) diff --git a/bson/bsonrw/value_reader.go b/bson/bsonrw/value_reader.go index a242bb57cf..0e07d50558 100644 --- a/bson/bsonrw/value_reader.go +++ b/bson/bsonrw/value_reader.go @@ -842,7 +842,7 @@ func (vr *valueReader) peekLength() (int32, error) { } idx := vr.offset - return (int32(vr.d[idx]) | int32(vr.d[idx+1])<<8 | int32(vr.d[idx+2])<<16 | int32(vr.d[idx+3])<<24), nil + return int32(binary.LittleEndian.Uint32(vr.d[idx:])), nil } func (vr *valueReader) readLength() (int32, error) { return vr.readi32() } @@ -854,7 +854,7 @@ func (vr *valueReader) readi32() (int32, error) { idx := vr.offset vr.offset += 4 - return (int32(vr.d[idx]) | int32(vr.d[idx+1])<<8 | int32(vr.d[idx+2])<<16 | int32(vr.d[idx+3])<<24), nil + return int32(binary.LittleEndian.Uint32(vr.d[idx:])), nil } func (vr *valueReader) readu32() (uint32, error) { @@ -864,7 +864,7 @@ func (vr *valueReader) readu32() (uint32, error) { idx := vr.offset vr.offset += 4 - return (uint32(vr.d[idx]) | uint32(vr.d[idx+1])<<8 | uint32(vr.d[idx+2])<<16 | uint32(vr.d[idx+3])<<24), nil + return binary.LittleEndian.Uint32(vr.d[idx:]), nil } func (vr *valueReader) readi64() (int64, error) { @@ -874,8 +874,7 @@ func (vr *valueReader) readi64() (int64, error) { idx := vr.offset vr.offset += 8 - return int64(vr.d[idx]) | int64(vr.d[idx+1])<<8 | int64(vr.d[idx+2])<<16 | int64(vr.d[idx+3])<<24 | - int64(vr.d[idx+4])<<32 | int64(vr.d[idx+5])<<40 | int64(vr.d[idx+6])<<48 | int64(vr.d[idx+7])<<56, nil + return int64(binary.LittleEndian.Uint64(vr.d[idx:])), nil } func (vr *valueReader) readu64() (uint64, error) { @@ -885,6 +884,5 @@ func (vr *valueReader) readu64() (uint64, error) { idx := vr.offset vr.offset += 8 - return uint64(vr.d[idx]) | uint64(vr.d[idx+1])<<8 | uint64(vr.d[idx+2])<<16 | uint64(vr.d[idx+3])<<24 | - uint64(vr.d[idx+4])<<32 | uint64(vr.d[idx+5])<<40 | uint64(vr.d[idx+6])<<48 | uint64(vr.d[idx+7])<<56, nil + return binary.LittleEndian.Uint64(vr.d[idx:]), nil } diff --git a/cmd/testatlas/main.go b/cmd/testatlas/atlas_test.go similarity index 82% rename from cmd/testatlas/main.go rename to cmd/testatlas/atlas_test.go index ae1b15fcbc..1b60c64769 100644 --- a/cmd/testatlas/main.go +++ b/cmd/testatlas/atlas_test.go @@ -11,6 +11,8 @@ import ( "errors" "flag" "fmt" + "os" + "testing" "time" "go.mongodb.org/mongo-driver/bson" @@ -19,15 +21,19 @@ import ( "go.mongodb.org/mongo-driver/mongo/options" ) -func main() { +func TestMain(m *testing.M) { flag.Parse() + os.Exit(m.Run()) +} + +func TestAtlas(t *testing.T) { uris := flag.Args() ctx := context.Background() - fmt.Printf("Running atlas tests for %d uris\n", len(uris)) + t.Logf("Running atlas tests for %d uris\n", len(uris)) for idx, uri := range uris { - fmt.Printf("Running test %d\n", idx) + t.Logf("Running test %d\n", idx) // Set a low server selection timeout so we fail fast if there are errors. clientOpts := options.Client(). @@ -36,18 +42,18 @@ func main() { // Run basic connectivity test. if err := runTest(ctx, clientOpts); err != nil { - panic(fmt.Sprintf("error running test with TLS at index %d: %v", idx, err)) + t.Fatalf("error running test with TLS at index %d: %v", idx, err) } // Run the connectivity test with InsecureSkipVerify to ensure SNI is done correctly even if verification is // disabled. clientOpts.TLSConfig.InsecureSkipVerify = true if err := runTest(ctx, clientOpts); err != nil { - panic(fmt.Sprintf("error running test with tlsInsecure at index %d: %v", idx, err)) + t.Fatalf("error running test with tlsInsecure at index %d: %v", idx, err) } } - fmt.Println("Finished!") + t.Logf("Finished!") } func runTest(ctx context.Context, clientOpts *options.ClientOptions) error { diff --git a/etc/run-atlas-test.sh b/etc/run-atlas-test.sh index 6ca6775b55..ae240f6cbf 100644 --- a/etc/run-atlas-test.sh +++ b/etc/run-atlas-test.sh @@ -7,5 +7,5 @@ set +x # Get the atlas secrets. . ${DRIVERS_TOOLS}/.evergreen/secrets_handling/setup-secrets.sh drivers/atlas_connect -echo "Running cmd/testatlas/main.go" -go run ./cmd/testatlas/main.go "$ATLAS_REPL" "$ATLAS_SHRD" "$ATLAS_FREE" "$ATLAS_TLS11" "$ATLAS_TLS12" "$ATLAS_SERVERLESS" "$ATLAS_SRV_REPL" "$ATLAS_SRV_SHRD" "$ATLAS_SRV_FREE" "$ATLAS_SRV_TLS11" "$ATLAS_SRV_TLS12" "$ATLAS_SRV_SERVERLESS" >> test.suite +echo "Running cmd/testatlas" +go test -v -run ^TestAtlas$ go.mongodb.org/mongo-driver/cmd/testatlas -args "$ATLAS_REPL" "$ATLAS_SHRD" "$ATLAS_FREE" "$ATLAS_TLS11" "$ATLAS_TLS12" "$ATLAS_SERVERLESS" "$ATLAS_SRV_REPL" "$ATLAS_SRV_SHRD" "$ATLAS_SRV_FREE" "$ATLAS_SRV_TLS11" "$ATLAS_SRV_TLS12" "$ATLAS_SRV_SERVERLESS" >> test.suite diff --git a/internal/logger/io_sink.go b/internal/logger/io_sink.go index c5ff1474b4..0a6c1bdcab 100644 --- a/internal/logger/io_sink.go +++ b/internal/logger/io_sink.go @@ -9,6 +9,7 @@ package logger import ( "encoding/json" "io" + "math" "sync" "time" ) @@ -36,7 +37,11 @@ func NewIOSink(out io.Writer) *IOSink { // Info will write a JSON-encoded message to the io.Writer. func (sink *IOSink) Info(_ int, msg string, keysAndValues ...interface{}) { - kvMap := make(map[string]interface{}, len(keysAndValues)/2+2) + mapSize := len(keysAndValues) / 2 + if math.MaxInt-mapSize >= 2 { + mapSize += 2 + } + kvMap := make(map[string]interface{}, mapSize) kvMap[KeyTimestamp] = time.Now().UnixNano() kvMap[KeyMessage] = msg diff --git a/mongo/options/clientoptions.go b/mongo/options/clientoptions.go index db56745919..17b3731301 100644 --- a/mongo/options/clientoptions.go +++ b/mongo/options/clientoptions.go @@ -15,6 +15,7 @@ import ( "errors" "fmt" "io/ioutil" + "math" "net" "net/http" "strings" @@ -1177,7 +1178,19 @@ func addClientCertFromSeparateFiles(cfg *tls.Config, keyFile, certFile, keyPassw return "", err } - data := make([]byte, 0, len(keyData)+len(certData)+1) + keySize := len(keyData) + if keySize > 64*1024*1024 { + return "", errors.New("X.509 key must be less than 64 MiB") + } + certSize := len(certData) + if certSize > 64*1024*1024 { + return "", errors.New("X.509 certificate must be less than 64 MiB") + } + dataSize := keySize + certSize + 1 + if dataSize > math.MaxInt { + return "", errors.New("size overflow") + } + data := make([]byte, 0, dataSize) data = append(data, keyData...) data = append(data, '\n') data = append(data, certData...) diff --git a/x/bsonx/bsoncore/bsoncore.go b/x/bsonx/bsoncore/bsoncore.go index 88133293ea..03925d7ada 100644 --- a/x/bsonx/bsoncore/bsoncore.go +++ b/x/bsonx/bsoncore/bsoncore.go @@ -8,6 +8,7 @@ package bsoncore // import "go.mongodb.org/mongo-driver/x/bsonx/bsoncore" import ( "bytes" + "encoding/binary" "fmt" "math" "strconv" @@ -706,17 +707,16 @@ func ReserveLength(dst []byte) (int32, []byte) { // UpdateLength updates the length at index with length and returns the []byte. func UpdateLength(dst []byte, index, length int32) []byte { - dst[index] = byte(length) - dst[index+1] = byte(length >> 8) - dst[index+2] = byte(length >> 16) - dst[index+3] = byte(length >> 24) + binary.LittleEndian.PutUint32(dst[index:], uint32(length)) return dst } func appendLength(dst []byte, l int32) []byte { return appendi32(dst, l) } func appendi32(dst []byte, i32 int32) []byte { - return append(dst, byte(i32), byte(i32>>8), byte(i32>>16), byte(i32>>24)) + b := []byte{0, 0, 0, 0} + binary.LittleEndian.PutUint32(b, uint32(i32)) + return append(dst, b...) } // ReadLength reads an int32 length from src and returns the length and the remaining bytes. If @@ -734,27 +734,26 @@ func readi32(src []byte) (int32, []byte, bool) { if len(src) < 4 { return 0, src, false } - return (int32(src[0]) | int32(src[1])<<8 | int32(src[2])<<16 | int32(src[3])<<24), src[4:], true + return int32(binary.LittleEndian.Uint32(src)), src[4:], true } func appendi64(dst []byte, i64 int64) []byte { - return append(dst, - byte(i64), byte(i64>>8), byte(i64>>16), byte(i64>>24), - byte(i64>>32), byte(i64>>40), byte(i64>>48), byte(i64>>56), - ) + b := []byte{0, 0, 0, 0, 0, 0, 0, 0} + binary.LittleEndian.PutUint64(b, uint64(i64)) + return append(dst, b...) } func readi64(src []byte) (int64, []byte, bool) { if len(src) < 8 { return 0, src, false } - i64 := (int64(src[0]) | int64(src[1])<<8 | int64(src[2])<<16 | int64(src[3])<<24 | - int64(src[4])<<32 | int64(src[5])<<40 | int64(src[6])<<48 | int64(src[7])<<56) - return i64, src[8:], true + return int64(binary.LittleEndian.Uint64(src)), src[8:], true } func appendu32(dst []byte, u32 uint32) []byte { - return append(dst, byte(u32), byte(u32>>8), byte(u32>>16), byte(u32>>24)) + b := []byte{0, 0, 0, 0} + binary.LittleEndian.PutUint32(b, u32) + return append(dst, b...) } func readu32(src []byte) (uint32, []byte, bool) { @@ -762,23 +761,20 @@ func readu32(src []byte) (uint32, []byte, bool) { return 0, src, false } - return (uint32(src[0]) | uint32(src[1])<<8 | uint32(src[2])<<16 | uint32(src[3])<<24), src[4:], true + return binary.LittleEndian.Uint32(src), src[4:], true } func appendu64(dst []byte, u64 uint64) []byte { - return append(dst, - byte(u64), byte(u64>>8), byte(u64>>16), byte(u64>>24), - byte(u64>>32), byte(u64>>40), byte(u64>>48), byte(u64>>56), - ) + b := []byte{0, 0, 0, 0, 0, 0, 0, 0} + binary.LittleEndian.PutUint64(b, u64) + return append(dst, b...) } func readu64(src []byte) (uint64, []byte, bool) { if len(src) < 8 { return 0, src, false } - u64 := (uint64(src[0]) | uint64(src[1])<<8 | uint64(src[2])<<16 | uint64(src[3])<<24 | - uint64(src[4])<<32 | uint64(src[5])<<40 | uint64(src[6])<<48 | uint64(src[7])<<56) - return u64, src[8:], true + return binary.LittleEndian.Uint64(src), src[8:], true } // keep in sync with readcstringbytes From 751a42eb2c6546c5a653c15eb5258de024367ff4 Mon Sep 17 00:00:00 2001 From: Steven Silvester Date: Fri, 28 Jun 2024 08:41:34 -0500 Subject: [PATCH 8/8] BUMP to v1.17.0-prerelease --- version/version.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/version/version.go b/version/version.go index 040c707064..6fb59e745f 100644 --- a/version/version.go +++ b/version/version.go @@ -8,4 +8,4 @@ package version // import "go.mongodb.org/mongo-driver/version" // Driver is the current version of the driver. -var Driver = "v1.16.0-prerelease" +var Driver = "v1.17.0-prerelease"