summaryrefslogtreecommitdiffstats
path: root/vendor/gopkg.in/asn1-ber.v1/length.go
diff options
context:
space:
mode:
Diffstat (limited to 'vendor/gopkg.in/asn1-ber.v1/length.go')
-rw-r--r--vendor/gopkg.in/asn1-ber.v1/length.go14
1 files changed, 12 insertions, 2 deletions
diff --git a/vendor/gopkg.in/asn1-ber.v1/length.go b/vendor/gopkg.in/asn1-ber.v1/length.go
index 8e2ae4ddd..750e8f443 100644
--- a/vendor/gopkg.in/asn1-ber.v1/length.go
+++ b/vendor/gopkg.in/asn1-ber.v1/length.go
@@ -38,6 +38,9 @@ func readLength(reader io.Reader) (length int, read int, err error) {
if lengthBytes > 8 {
return 0, read, errors.New("long-form length overflow")
}
+
+ // Accumulate into a 64-bit variable
+ var length64 int64
for i := 0; i < lengthBytes; i++ {
b, err = readByte(reader)
if err != nil {
@@ -49,8 +52,15 @@ func readLength(reader io.Reader) (length int, read int, err error) {
read++
// x.600, 8.1.3.5
- length <<= 8
- length |= int(b)
+ length64 <<= 8
+ length64 |= int64(b)
+ }
+
+ // Cast to a platform-specific integer
+ length = int(length64)
+ // Ensure we didn't overflow
+ if int64(length) != length64 {
+ return 0, read, errors.New("long-form length overflow")
}
default: