mirror of
https://github.com/btcsuite/btcd.git
synced 2026-08-13 12:32:51 +02:00
psbt: limit value size in ReadTaprootBip32Derivation to prevent OOM
Cap the `value` slice to `MaxPsbtValueLength` to prevent potential out-of-memory conditions during parsing. This ensures that total allocation remains bounded and consistent with other PSBT fields.
This commit is contained in:
parent
16c2b92afd
commit
565a7a8822
1 changed files with 7 additions and 0 deletions
|
|
@ -143,6 +143,13 @@ func minTaprootBip32DerivationByteSize(numHashes uint64) (uint64, error) {
|
|||
func ReadTaprootBip32Derivation(xOnlyPubKey,
|
||||
value []byte) (*TaprootBip32Derivation, error) {
|
||||
|
||||
// This function allocates additional memory while parsing the serialized
|
||||
// data. To prevent potential out-of-memory (OOM) issues, we must validate
|
||||
// the length of the value slice before proceeding.
|
||||
if len(value) > MaxPsbtValueLength {
|
||||
return nil, ErrInvalidPsbtFormat
|
||||
}
|
||||
|
||||
// The taproot key BIP 32 derivation path is defined as:
|
||||
// <hashes len> <leaf hash>* <4 byte fingerprint> <32-bit uint>*
|
||||
// So we get at least 5 bytes for the length and the 4 byte fingerprint.
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue