Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion rust/chains/tw_pactus/src/types/amount.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,15 @@ pub struct Amount(pub i64);

impl Encodable for Amount {
fn encode(&self, w: &mut dyn std::io::Write) -> Result<(), Error> {
VarInt::from(self.0 as usize).encode(w)
let amount: usize = match self.0.try_into() {
Ok(amount) => amount,
Err(_) => {
return Err(Error::IoError(std::io::Error::from(
std::io::ErrorKind::InvalidInput,
)));
},
};
VarInt::from(amount).encode(w)
}

fn encoded_size(&self) -> usize {
Expand Down
4 changes: 3 additions & 1 deletion src/BinaryCoding.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,9 @@ tuple<bool, string> decodeString(const Data& in, size_t& indexInOut) {
if (!get<0>(lenTup)) { return make_tuple(false, ""); }
const auto len = get<1>(lenTup);
// read bytes into string
if (in.size() < indexInOut + len) { return make_tuple(false, ""); }
if (in.size() < indexInOut || in.size() - indexInOut < len) {
return make_tuple(false, "");
}
string result(in.data() + indexInOut, in.data() + indexInOut + len);
indexInOut += len;
return make_tuple(true, result);
Expand Down
Loading