base64decode: check that the decoded (not encoded) string is valid UTF-8
This commit is contained in:
parent
6171ba3b8a
commit
74f2d58b8b
|
@ -5,6 +5,7 @@ import (
|
||||||
"compress/gzip"
|
"compress/gzip"
|
||||||
"encoding/base64"
|
"encoding/base64"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"log"
|
||||||
"net/url"
|
"net/url"
|
||||||
"unicode/utf8"
|
"unicode/utf8"
|
||||||
|
|
||||||
|
@ -27,8 +28,9 @@ var Base64DecodeFunc = function.New(&function.Spec{
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return cty.UnknownVal(cty.String), fmt.Errorf("failed to decode base64 data '%s'", s)
|
return cty.UnknownVal(cty.String), fmt.Errorf("failed to decode base64 data '%s'", s)
|
||||||
}
|
}
|
||||||
if !utf8.Valid([]byte(s)) {
|
if !utf8.Valid([]byte(sDec)) {
|
||||||
return cty.UnknownVal(cty.String), fmt.Errorf("contents of '%s' are not valid UTF-8", s)
|
log.Printf("[DEBUG] the result of decoding the the provided string is not valid UTF-8: %s", sDec)
|
||||||
|
return cty.UnknownVal(cty.String), fmt.Errorf("the result of decoding the the provided string is not valid UTF-8")
|
||||||
}
|
}
|
||||||
return cty.StringVal(string(sDec)), nil
|
return cty.StringVal(string(sDec)), nil
|
||||||
},
|
},
|
||||||
|
|
Loading…
Reference in New Issue