Skip to content

Commit 4cd2cc6

Browse files
committed
fix: Use base64 to encode not utf-8 bytes
See also: #45654 Signed-off-by: yangxuan <[email protected]>
1 parent 386ca2e commit 4cd2cc6

File tree

5 files changed

+11
-6
lines changed

5 files changed

+11
-6
lines changed

internal/flushcommon/syncmgr/pack_writer_v2.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ package syncmgr
1818

1919
import (
2020
"context"
21+
"encoding/base64"
2122
"math"
2223

2324
"github.com/apache/arrow/go/v17/arrow/array"
@@ -167,7 +168,7 @@ func (bw *BulkPackWriterV2) writeInserts(ctx context.Context, pack *SyncPack) (m
167168
pluginContext := indexcgopb.StoragePluginContext{
168169
EncryptionZoneId: ez.EzID,
169170
CollectionId: ez.CollectionID,
170-
EncryptionKey: string(unsafe),
171+
EncryptionKey: base64.StdEncoding.EncodeToString(unsafe),
171172
}
172173
pluginContextPtr = &pluginContext
173174
}

internal/querynodev2/segments/collection.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
package segments
1818

1919
import (
20+
"encoding/base64"
2021
"fmt"
2122
"sync"
2223

@@ -398,7 +399,7 @@ func putOrUpdateStorageContext(properties []*commonpb.KeyValuePair, collectionID
398399
ez := hookutil.GetEzByCollProperties(properties, collectionID)
399400
if ez != nil {
400401
key := hookutil.GetCipher().GetUnsafeKey(ez.EzID, ez.CollectionID)
401-
err := segcore.PutOrRefPluginContext(ez, string(key))
402+
err := segcore.PutOrRefPluginContext(ez, base64.StdEncoding.EncodeToString(key))
402403
if err != nil {
403404
log.Error("failed to put or update plugin context", zap.Int64("collectionID", collectionID), zap.Error(err))
404405
}

internal/storage/rw.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ package storage
1818

1919
import (
2020
"context"
21+
"encoding/base64"
2122
"fmt"
2223
sio "io"
2324
"sort"
@@ -253,7 +254,7 @@ func NewBinlogRecordReader(ctx context.Context, binlogs []*datapb.FieldBinlog, s
253254
pluginContext = &indexcgopb.StoragePluginContext{
254255
EncryptionZoneId: ez.EzID,
255256
CollectionId: ez.CollectionID,
256-
EncryptionKey: string(unsafe),
257+
EncryptionKey: base64.StdEncoding.EncodeToString(unsafe),
257258
}
258259
}
259260
}
@@ -326,7 +327,7 @@ func NewBinlogRecordWriter(ctx context.Context, collectionID, partitionID, segme
326327
pluginContext = &indexcgopb.StoragePluginContext{
327328
EncryptionZoneId: ez.EzID,
328329
CollectionId: ez.CollectionID,
329-
EncryptionKey: string(unsafe),
330+
EncryptionKey: base64.StdEncoding.EncodeToString(unsafe),
330331
}
331332
}
332333
}

internal/util/hookutil/cipher.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ package hookutil
1919
import (
2020
"bytes"
2121
"context"
22+
"encoding/base64"
2223
"fmt"
2324
"plugin"
2425
"strconv"
@@ -132,7 +133,7 @@ func GetStoragePluginContext(properties []*commonpb.KeyValuePair, collectionID i
132133
},
133134
{
134135
Key: CipherConfigUnsafeEZK,
135-
Value: string(key),
136+
Value: base64.StdEncoding.EncodeToString(key),
136137
},
137138
}
138139
return pluginContext

internal/util/hookutil/cipher_test.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ package hookutil
1818

1919
import (
2020
"context"
21+
"encoding/base64"
2122
"fmt"
2223
"sync"
2324
"testing"
@@ -243,7 +244,7 @@ func (s *CipherSuite) TestGetStoragePluginContext() {
243244
s.Equal(CipherConfigCreateEZ, result[0].Key)
244245
s.Equal("1", result[0].Value)
245246
s.Equal(CipherConfigUnsafeEZK, result[1].Key)
246-
s.Equal("unsafe key", result[1].Value)
247+
s.Equal(base64.StdEncoding.EncodeToString([]byte("unsafe key")), result[1].Value)
247248

248249
result = GetStoragePluginContext([]*commonpb.KeyValuePair{}, 2)
249250
s.Nil(result)

0 commit comments

Comments
 (0)