You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@thrift.apache.org by je...@apache.org on 2015/07/10 02:01:33 UTC

thrift git commit: THRIFT-3236 MaxSkipDepth never checked Client: Go Patch: Jens Geyer

Repository: thrift
Updated Branches:
  refs/heads/master 401803698 -> 3ea26be2a


THRIFT-3236 MaxSkipDepth never checked
Client: Go
Patch: Jens Geyer


Project: http://git-wip-us.apache.org/repos/asf/thrift/repo
Commit: http://git-wip-us.apache.org/repos/asf/thrift/commit/3ea26be2
Tree: http://git-wip-us.apache.org/repos/asf/thrift/tree/3ea26be2
Diff: http://git-wip-us.apache.org/repos/asf/thrift/diff/3ea26be2

Branch: refs/heads/master
Commit: 3ea26be2ae08c2c7992137e5142cec146627e119
Parents: 4018036
Author: Jens Geyer <je...@apache.org>
Authored: Fri Jul 10 00:23:39 2015 +0200
Committer: Jens Geyer <je...@apache.org>
Committed: Fri Jul 10 02:00:36 2015 +0200

----------------------------------------------------------------------
 lib/go/thrift/protocol.go | 33 +++++++++++++++++++++++++++------
 1 file changed, 27 insertions(+), 6 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/thrift/blob/3ea26be2/lib/go/thrift/protocol.go
----------------------------------------------------------------------
diff --git a/lib/go/thrift/protocol.go b/lib/go/thrift/protocol.go
index 87ceaad..6fb0177 100644
--- a/lib/go/thrift/protocol.go
+++ b/lib/go/thrift/protocol.go
@@ -19,6 +19,10 @@
 
 package thrift
 
+import (
+	"errors"
+)
+
 const (
 	VERSION_MASK = 0xffff0000
 	VERSION_1    = 0x80010000
@@ -75,15 +79,20 @@ type TProtocol interface {
 }
 
 // The maximum recursive depth the skip() function will traverse
-var MaxSkipDepth = 1<<31 - 1
+const DEFAULT_RECURSION_DEPTH = 64
 
 // Skips over the next data element from the provided input TProtocol object.
 func SkipDefaultDepth(prot TProtocol, typeId TType) (err error) {
-	return Skip(prot, typeId, MaxSkipDepth)
+	return Skip(prot, typeId, DEFAULT_RECURSION_DEPTH)
 }
 
 // Skips over the next data element from the provided input TProtocol object.
 func Skip(self TProtocol, fieldType TType, maxDepth int) (err error) {
+	
+    if maxDepth <= 0 {
+		return NewTProtocolExceptionWithType( DEPTH_LIMIT, errors.New("Depth limit exceeded"))
+	}
+
 	switch fieldType {
 	case STOP:
 		return
@@ -117,7 +126,10 @@ func Skip(self TProtocol, fieldType TType, maxDepth int) (err error) {
 			if typeId == STOP {
 				break
 			}
-			Skip(self, typeId, maxDepth-1)
+			err := Skip(self, typeId, maxDepth-1)
+			if err != nil {
+				return err
+			}
 			self.ReadFieldEnd()
 		}
 		return self.ReadStructEnd()
@@ -127,7 +139,10 @@ func Skip(self TProtocol, fieldType TType, maxDepth int) (err error) {
 			return err
 		}
 		for i := 0; i < size; i++ {
-			Skip(self, keyType, maxDepth-1)
+			err := Skip(self, keyType, maxDepth-1)
+			if err != nil {
+				return err
+			}
 			self.Skip(valueType)
 		}
 		return self.ReadMapEnd()
@@ -137,7 +152,10 @@ func Skip(self TProtocol, fieldType TType, maxDepth int) (err error) {
 			return err
 		}
 		for i := 0; i < size; i++ {
-			Skip(self, elemType, maxDepth-1)
+			err := Skip(self, elemType, maxDepth-1)
+			if err != nil {
+				return err
+			}
 		}
 		return self.ReadSetEnd()
 	case LIST:
@@ -146,7 +164,10 @@ func Skip(self TProtocol, fieldType TType, maxDepth int) (err error) {
 			return err
 		}
 		for i := 0; i < size; i++ {
-			Skip(self, elemType, maxDepth-1)
+			err := Skip(self, elemType, maxDepth-1)
+			if err != nil {
+				return err
+			}
 		}
 		return self.ReadListEnd()
 	}