Skip to content

Commit

Permalink
Merge pull request #100 from bitshares/fix-to-long
Browse files Browse the repository at this point in the history
In to_long(), validate return of Long.fromString()
  • Loading branch information
sschiessl-bcp committed Nov 21, 2023
2 parents a4e92f1 + 55d72a8 commit 2b26fbb
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion lib/serializer/src/SerializerValidation.js
Original file line number Diff line number Diff line change
Expand Up @@ -109,10 +109,20 @@ var _my = {
}

this.no_overflow64(value, field_name, unsigned);
// BigInteger#isBigInteger https://github.com/cryptocoinjs/bigi/issues/20
// (code copied from no_overflow64)
if (value.t !== undefined && value.s !== undefined) {
value = value.toString();
}
if (typeof value === "number") {
value = "" + value;
}
return Long.fromString(value, unsigned);
value = value.trim();
var long_value = Long.fromString(value, unsigned);
if (long_value.toString() !== value) {
throw new Error(`Unable to safely convert ${field_name} ${value} to long`);
}
return long_value;
},

to_string(value, field_name = "") {
Expand Down

0 comments on commit 2b26fbb

Please sign in to comment.