Description
- in func Binary.GetContentBytes of binary.go:
decoded := make([]byte, base64.StdEncoding.DecodedLen(len(b.Content)))
_, err := base64.StdEncoding.Decode(decoded, b.Content)
the base64.StdEncoding.DecodedLen return enough length to hold result, not actually size, maybe we should not discard the return length from base64.StdEncoding.Decode, that's actually size.
when b.Compressed.Bool is true, the ioutil.ReadAll() return's error io.ErrUnexpectedEOF may should not be ignored, it will cover the following bug in SetContent().
- in func Binary.SetContent of binary.go:
writer = base64.NewEncoder(base64.StdEncoding, buff)
the writer of base64 should be closed after the gzip writer closed, else it may left some bytes un-flushed. this will cause some binary attachement was zero bytes in other keepass tool, such as KeePassXC.
if we use Binary.GetContentBytes to test the result of Binary.SetContent, it will be success because Binary.GetContentBytes ignore io.ErrUnexpectedEOF returned by ioutil.ReadAll(), I don't know is there anyother case that we should ignore it, but in this case, it shouldn't.
the following case will cause un-flushed bytes when using WithDatabaseKDBXVersion3:
randomData := make([]byte, 7945)
rand.Read(randomData)