diff options
author | Chong Cai <chongc@google.com> | 2020-11-04 11:39:07 -0800 |
---|---|---|
committer | gVisor bot <gvisor-bot@google.com> | 2020-11-04 11:41:38 -0800 |
commit | a15562c019a42e04fed7e9cff1d901b3bcfaca59 (patch) | |
tree | 04e7da5d587377af6427d08bc3811ff547482270 /pkg/merkletree/merkletree.go | |
parent | 3b18bdbd3c119e8fe10e21587374cca3b08f0020 (diff) |
Include file size in Merkle hash
The file size can now also be verified. Also, since we are zero-padding
the last block of the data, we cannot differentiate the cases between
zero-padded block from the blocks that are ends with zeroes. With the
size included this can be addressed, as those cases would have different
file size.
PiperOrigin-RevId: 340695510
Diffstat (limited to 'pkg/merkletree/merkletree.go')
-rw-r--r-- | pkg/merkletree/merkletree.go | 14 |
1 files changed, 9 insertions, 5 deletions
diff --git a/pkg/merkletree/merkletree.go b/pkg/merkletree/merkletree.go index 18457d287..e0a9e56c5 100644 --- a/pkg/merkletree/merkletree.go +++ b/pkg/merkletree/merkletree.go @@ -147,6 +147,7 @@ func (layout Layout) blockOffset(level int, index int64) int64 { // meatadata. type VerityDescriptor struct { Name string + FileSize int64 Mode uint32 UID uint32 GID uint32 @@ -154,7 +155,7 @@ type VerityDescriptor struct { } func (d *VerityDescriptor) String() string { - return fmt.Sprintf("Name: %s, Mode: %d, UID: %d, GID: %d, RootHash: %v", d.Name, d.Mode, d.UID, d.GID, d.RootHash) + return fmt.Sprintf("Name: %s, Size: %d, Mode: %d, UID: %d, GID: %d, RootHash: %v", d.Name, d.FileSize, d.Mode, d.UID, d.GID, d.RootHash) } // verify generates a hash from d, and compares it with expected. @@ -289,6 +290,7 @@ func Generate(params *GenerateParams) ([]byte, error) { } descriptor := VerityDescriptor{ Name: params.Name, + FileSize: params.Size, Mode: params.Mode, UID: params.UID, GID: params.GID, @@ -342,6 +344,7 @@ func verifyMetadata(params *VerifyParams, layout *Layout) error { } descriptor := VerityDescriptor{ Name: params.Name, + FileSize: params.Size, Mode: params.Mode, UID: params.UID, GID: params.GID, @@ -401,10 +404,11 @@ func Verify(params *VerifyParams) (int64, error) { } } descriptor := VerityDescriptor{ - Name: params.Name, - Mode: params.Mode, - UID: params.UID, - GID: params.GID, + Name: params.Name, + FileSize: params.Size, + Mode: params.Mode, + UID: params.UID, + GID: params.GID, } if err := verifyBlock(params.Tree, &descriptor, &layout, buf, i, params.HashAlgorithms, params.Expected); err != nil { return 0, err |