Skip to content

Commit b5e9567

Browse files
authored
fix: Ensure minimum array length in BigNumber to prevent crashes with zero-length buffers (#81)
1 parent 0757482 commit b5e9567

File tree

1 file changed

+2
-1
lines changed

1 file changed

+2
-1
lines changed

src/BigNumber.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -240,7 +240,8 @@ export class BN {
240240
return this.toArray(endian, len);
241241
}
242242

243-
const outLen = len != null ? len : this.byteLength();
243+
// Ensure minimum array length of 1 to prevent native crashes with zero-length buffers
244+
const outLen = len != null ? len : Math.max(1, this.byteLength());
244245

245246
const res = new (arrayLike as any)(outLen);
246247

0 commit comments

Comments
 (0)