Skip to content

Commit 2b26fbb

Browse files
Merge pull request #100 from bitshares/fix-to-long
In to_long(), validate return of Long.fromString()
2 parents a4e92f1 + 55d72a8 commit 2b26fbb

File tree

1 file changed

+11
-1
lines changed

1 file changed

+11
-1
lines changed

lib/serializer/src/SerializerValidation.js

+11-1
Original file line numberDiff line numberDiff line change
@@ -109,10 +109,20 @@ var _my = {
109109
}
110110

111111
this.no_overflow64(value, field_name, unsigned);
112+
// BigInteger#isBigInteger https://github.com/cryptocoinjs/bigi/issues/20
113+
// (code copied from no_overflow64)
114+
if (value.t !== undefined && value.s !== undefined) {
115+
value = value.toString();
116+
}
112117
if (typeof value === "number") {
113118
value = "" + value;
114119
}
115-
return Long.fromString(value, unsigned);
120+
value = value.trim();
121+
var long_value = Long.fromString(value, unsigned);
122+
if (long_value.toString() !== value) {
123+
throw new Error(`Unable to safely convert ${field_name} ${value} to long`);
124+
}
125+
return long_value;
116126
},
117127

118128
to_string(value, field_name = "") {

0 commit comments

Comments
 (0)