@@ -29,6 +29,7 @@ import (
29
29
"sort"
30
30
"strconv"
31
31
"strings"
32
+ "unicode/utf8"
32
33
33
34
rpc "github.com/cs3org/go-cs3apis/cs3/rpc/v1beta1"
34
35
provider "github.com/cs3org/go-cs3apis/cs3/storage/provider/v1beta1"
@@ -800,6 +801,7 @@ func (s *service) Stat(ctx context.Context, req *provider.StatRequest) (*provide
800
801
}, nil
801
802
}
802
803
s .fixPermissions (md )
804
+ s .stripNonUtf8Metadata (ctx , md )
803
805
res := & provider.StatResponse {
804
806
Status : status .NewOK (ctx ),
805
807
Info : md ,
@@ -826,6 +828,28 @@ func (s *service) fixPermissions(md *provider.ResourceInfo) {
826
828
}
827
829
}
828
830
831
+ // This method removes any entries in the ArbitraryMetadata map that
832
+ // are not valid UTF-8
833
+ // This is necessary because protobuf requires strings to only contain valid UTF-8
834
+ func (s * service ) stripNonUtf8Metadata (ctx context.Context , md * provider.ResourceInfo ) {
835
+ log := appctx .GetLogger (ctx )
836
+ if md .ArbitraryMetadata == nil {
837
+ return
838
+ }
839
+
840
+ toDelete := []string {}
841
+ for k , v := range md .ArbitraryMetadata .Metadata {
842
+ if ! utf8 .ValidString (v ) {
843
+ toDelete = append (toDelete , k )
844
+ }
845
+ }
846
+
847
+ for _ , k := range toDelete {
848
+ log .Debug ().Str ("attribute" , k ).Msg ("Dropping non-UTF8 metadata entry" )
849
+ delete (md .ArbitraryMetadata .Metadata , k )
850
+ }
851
+ }
852
+
829
853
func (s * service ) statVirtualView (ctx context.Context , ref * provider.Reference ) (* provider.StatResponse , error ) {
830
854
// The reference in the request encompasses this provider
831
855
// So we need to stat root, and update the required path
@@ -945,7 +969,7 @@ func (s *service) ListContainer(ctx context.Context, req *provider.ListContainer
945
969
case errtypes.PermissionDenied :
946
970
st = status .NewPermissionDenied (ctx , err , "permission denied" )
947
971
default :
948
- log .Error ().Str ( "path " , newRef . Path ).Err (err ).Msg ("storageprovider: error listing container" )
972
+ log .Error ().Any ( "ref " , newRef ).Err (err ).Msg ("storageprovider: error listing container" )
949
973
st = status .NewInternal (ctx , err , "error listing container: " + req .Ref .String ())
950
974
}
951
975
return & provider.ListContainerResponse {
@@ -962,6 +986,7 @@ func (s *service) ListContainer(ctx context.Context, req *provider.ListContainer
962
986
}, nil
963
987
}
964
988
s .fixPermissions (md )
989
+ s .stripNonUtf8Metadata (ctx , md )
965
990
infos = append (infos , md )
966
991
}
967
992
res := & provider.ListContainerResponse {
0 commit comments