Skip to content

Commit af2f6e1

Browse files
authored
fix: don't check Byron address length (#539)
Fixes #538
1 parent 8ee9e6f commit af2f6e1

File tree

1 file changed

+21
-12
lines changed

1 file changed

+21
-12
lines changed

ledger/common.go

Lines changed: 21 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -256,26 +256,35 @@ func NewAddressFromParts(
256256
}
257257

258258
func (a *Address) populateFromBytes(data []byte) error {
259-
// Check length
260-
dataLen := len(data)
261-
if dataLen < (AddressHashSize + 1) {
262-
return fmt.Errorf("invalid address length: %d", dataLen)
263-
}
264-
if dataLen > (AddressHashSize + 1) {
265-
if dataLen < (AddressHashSize + AddressHashSize + 1) {
266-
return fmt.Errorf("invalid address length: %d", dataLen)
267-
}
268-
}
269259
// Extract header info
270260
header := data[0]
271261
a.addressType = (header & AddressHeaderTypeMask) >> 4
272262
a.networkId = header & AddressHeaderNetworkMask
263+
// Check length
264+
// We exclude a few address types without fixed sizes that we don't properly support yet
265+
if a.addressType != AddressTypeByron &&
266+
a.addressType != AddressTypeKeyPointer &&
267+
a.addressType != AddressTypeScriptPointer {
268+
dataLen := len(data)
269+
if dataLen < (AddressHashSize + 1) {
270+
return fmt.Errorf("invalid address length: %d", dataLen)
271+
}
272+
if dataLen > (AddressHashSize + 1) {
273+
if dataLen < (AddressHashSize + AddressHashSize + 1) {
274+
return fmt.Errorf("invalid address length: %d", dataLen)
275+
}
276+
}
277+
}
273278
// Extract payload
274-
// NOTE: this is probably incorrect for Byron
279+
// NOTE: this is definitely incorrect for Byron
275280
payload := data[1:]
276281
a.paymentAddress = payload[:AddressHashSize]
277282
if len(payload) > AddressHashSize {
278-
a.stakingAddress = payload[AddressHashSize : AddressHashSize+AddressHashSize]
283+
stakingPayloadSize := len(payload) - AddressHashSize
284+
if stakingPayloadSize > AddressHashSize {
285+
stakingPayloadSize = AddressHashSize
286+
}
287+
a.stakingAddress = payload[AddressHashSize : AddressHashSize+stakingPayloadSize]
279288
}
280289
// Store any extra address data
281290
// This is needed to handle the case describe in:

0 commit comments

Comments
 (0)