ensure `ValidatorPubKey` int-compatibly aligned to fix UB (#5277)

* ensure ValidatorPubKey int-compatibly aligned

* use sizeof(Hash) explicitly
This commit is contained in:
tersec 2023-08-08 19:01:32 +00:00 committed by GitHub
parent f8520c8b1c
commit 8c3d1cd3aa
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 4 additions and 1 deletions

View File

@ -54,7 +54,10 @@ type
## eagerly load keys - deserialization is slow, as are equality checks -
## however, it is not guaranteed that the key is valid (except in some
## cases, like the database state)
blob*: array[RawPubKeySize, byte]
##
## It must be 8-byte aligned because `hash(ValidatorPubKey)` just casts a
## ptr to one to a ptr to the other, so it needs a compatible alignment.
blob* {.align: sizeof(Hash).}: array[RawPubKeySize, byte]
UncompressedPubKey* = object
## Uncompressed variation of ValidatorPubKey - this type is faster to