Skip to content

Commit

Permalink
Fix ToUsize conversions on 32-bit.
Browse files Browse the repository at this point in the history
  • Loading branch information
jeandudey committed Dec 12, 2024
1 parent e663615 commit 62b1879
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 3 deletions.
11 changes: 9 additions & 2 deletions psbt/src/parser/input.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ use bitcoin_hashes::{hash160, ripemd160, sha256, sha256d};

use nom::branch::alt;
use nom::bytes::complete::tag;
use nom::combinator::{eof, map, rest};
use nom::combinator::{eof, map, map_res, rest};
use nom::error::{context, ContextError, ErrorKind, FromExternalError, ParseError};
use nom::multi::length_value;
use nom::number::complete::{le_u32, le_u64};
Expand Down Expand Up @@ -219,11 +219,18 @@ where
+ Slice<core::ops::RangeFrom<usize>>,
Error: ParseError<Input>,
Error: ContextError<Input>,
Error: FromExternalError<Input, TryFromIntError>,
{
let amount = context("amount", le_u64);
let script_pubkey = context(
"script pubkey",
length_value(context("script pubkey length", compact_size), rest),
length_value(
context(
"script pubkey length",
map_res(compact_size, usize::try_from),
),
rest,
),
);

map(tuple((amount, script_pubkey)), |(amount, script_pubkey)| {
Expand Down
2 changes: 1 addition & 1 deletion psbt/src/parser/keypair.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ where
E: ParseError<I> + ContextError<I> + FromExternalError<I, TryFromIntError>,
{
let value = length_value(
map_res(compact_size, |v| usize::try_from(v)),
map_res(compact_size, usize::try_from),
context("when parsing value", value),
);

Expand Down

0 comments on commit 62b1879

Please sign in to comment.