mirror of
https://github.com/LBRYFoundation/lbcutil.git
synced 2025-08-23 17:47:30 +00:00
Merge pull request #163 from Crypt-iQ/psbt_fixes_0409
psbt: fix two deserialization bugs
This commit is contained in:
commit
b2bf7f89d6
3 changed files with 15 additions and 0 deletions
|
@ -141,6 +141,12 @@ func (pi *PInput) deserialize(r io.Reader) error {
|
||||||
return ErrInvalidKeydata
|
return ErrInvalidKeydata
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Bounds check on value here since the sighash type must be a
|
||||||
|
// 32-bit unsigned integer.
|
||||||
|
if len(value) != 4 {
|
||||||
|
return ErrInvalidKeydata
|
||||||
|
}
|
||||||
|
|
||||||
shtype := txscript.SigHashType(
|
shtype := txscript.SigHashType(
|
||||||
binary.LittleEndian.Uint32(value),
|
binary.LittleEndian.Uint32(value),
|
||||||
)
|
)
|
||||||
|
|
|
@ -33,6 +33,10 @@ var (
|
||||||
//less than 4M.
|
//less than 4M.
|
||||||
const MaxPsbtValueLength = 4000000
|
const MaxPsbtValueLength = 4000000
|
||||||
|
|
||||||
|
// MaxPsbtKeyLength is the length of the largest key that we'll successfully
|
||||||
|
// deserialize from the wire. Anything more will return ErrInvalidKeydata.
|
||||||
|
const MaxPsbtKeyLength = 10000
|
||||||
|
|
||||||
var (
|
var (
|
||||||
|
|
||||||
// ErrInvalidPsbtFormat is a generic error for any situation in which a
|
// ErrInvalidPsbtFormat is a generic error for any situation in which a
|
||||||
|
|
|
@ -237,6 +237,11 @@ func getKey(r io.Reader) (int, []byte, error) {
|
||||||
return -1, nil, nil
|
return -1, nil, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Check that we don't attempt to decode a dangerously large key.
|
||||||
|
if count > MaxPsbtKeyLength {
|
||||||
|
return -1, nil, ErrInvalidKeydata
|
||||||
|
}
|
||||||
|
|
||||||
// Next, we ready out the designated number of bytes, which may include
|
// Next, we ready out the designated number of bytes, which may include
|
||||||
// a type, key, and optional data.
|
// a type, key, and optional data.
|
||||||
keyTypeAndData := make([]byte, count)
|
keyTypeAndData := make([]byte, count)
|
||||||
|
|
Loading…
Add table
Reference in a new issue