Skip to content

Commit

Permalink
[fix]: Fixed deserialization issues cause by bytes misalignment due t…
Browse files Browse the repository at this point in the history
…o u64 (as opposed to i128) assumptions.
  • Loading branch information
batconjurer committed Jun 26, 2023
1 parent 64caae7 commit 9320c6b
Showing 1 changed file with 6 additions and 6 deletions.
12 changes: 6 additions & 6 deletions masp_primitives/src/transaction/components/transparent.rs
Original file line number Diff line number Diff line change
Expand Up @@ -105,10 +105,10 @@ impl TxIn<Authorized> {
pub fn read<R: Read>(reader: &mut R) -> io::Result<Self> {
let asset_type = AssetType::read(reader)?;
let value = {
assert_eq!(core::mem::size_of::<u64>(), 8);
let mut tmp = [0u8; core::mem::size_of::<u64>()];
assert_eq!(core::mem::size_of::<i128>(), 16);
let mut tmp = [0u8; core::mem::size_of::<i128>()];
reader.read_exact(&mut tmp)?;
u64::from_le_bytes(tmp).into()
i128::from_le_bytes(tmp).into()
};
if value < 0 || value > MAX_MONEY {
return Err(io::Error::new(
Expand Down Expand Up @@ -148,10 +148,10 @@ impl TxOut {
pub fn read<R: Read>(reader: &mut R) -> io::Result<Self> {
let asset_type = AssetType::read(reader)?;
let value = {
assert_eq!(core::mem::size_of::<u64>(), 8);
let mut tmp = [0u8; core::mem::size_of::<u64>()];
assert_eq!(core::mem::size_of::<i128>(), 16);
let mut tmp = [0u8; core::mem::size_of::<i128>()];
reader.read_exact(&mut tmp)?;
u64::from_le_bytes(tmp).into()
i128::from_le_bytes(tmp).into()
};
if value < 0 || value > MAX_MONEY {
return Err(io::Error::new(
Expand Down

0 comments on commit 9320c6b

Please sign in to comment.