summaryrefslogtreecommitdiff
path: root/lib/btrfs/types_node.go
diff options
context:
space:
mode:
Diffstat (limited to 'lib/btrfs/types_node.go')
-rw-r--r--lib/btrfs/types_node.go8
1 files changed, 8 insertions, 0 deletions
diff --git a/lib/btrfs/types_node.go b/lib/btrfs/types_node.go
index 9f20ea9..f425460 100644
--- a/lib/btrfs/types_node.go
+++ b/lib/btrfs/types_node.go
@@ -128,9 +128,17 @@ func (node *Node) UnmarshalBinary(nodeBuf []byte) (int, error) {
Size: uint32(len(nodeBuf)),
ChecksumType: node.ChecksumType,
}
+ if len(nodeBuf) <= binstruct.StaticSize(NodeHeader{}) {
+ return 0, fmt.Errorf("size must be greater than %v, but is %v",
+ binstruct.StaticSize(NodeHeader{}),
+ len(nodeBuf))
+ }
n, err := binstruct.Unmarshal(nodeBuf, &node.Head)
if err != nil {
return n, err
+ } else if n != binstruct.StaticSize(NodeHeader{}) {
+ return n, fmt.Errorf("header consumed %v bytes but expected %v",
+ n, binstruct.StaticSize(NodeHeader{}))
}
if node.Head.Level > 0 {
_n, err := node.unmarshalInternal(nodeBuf[n:])