Skip to content

Commit cb7f09f

Browse files
committed
Fix BigInteger.modInverse DoS in shipped bundles
1 parent 5d67719 commit cb7f09f

1 file changed

Lines changed: 24 additions & 0 deletions

File tree

npm/test/t_biginteger.js

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
var assert = require('assert');
2+
var path = require('path');
3+
var spawnSync = require('child_process').spawnSync;
4+
5+
describe("BigInteger", function() {
6+
it('modInverse(0, odd) should return 0 without hanging', function() {
7+
var childCode = [
8+
"var rs = require('./lib/jsrsasign.js');",
9+
"var a = new rs.BigInteger('0', 10);",
10+
"var m = new rs.BigInteger('9', 10);",
11+
"process.stdout.write(a.modInverse(m).toString(10));"
12+
].join('\n');
13+
14+
var result = spawnSync(process.execPath, ['-e', childCode], {
15+
cwd: path.resolve(__dirname, '..'),
16+
encoding: 'utf8',
17+
timeout: 1500
18+
});
19+
20+
assert.notEqual(result.error && result.error.code, 'ETIMEDOUT');
21+
assert.equal(result.status, 0);
22+
assert.equal(result.stdout, '0');
23+
});
24+
});

0 commit comments

Comments
 (0)