Skip to content

Commit 4cf6b7e

Browse files
committed
Change upload temporary file path generation to use crypto.randomBytes().
This should resolve an issue when using the Node cluster module, and two workers get forked with the same random seed, and the two processes' upload paths collide. This also resolves the (somewhat confused) complaints of #247.
1 parent 5bf869a commit 4cf6b7e

1 file changed

Lines changed: 5 additions & 3 deletions

File tree

lib/incoming_form.js

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
if (global.GENTLY) require = GENTLY.hijack(require);
22

3+
var crypto = require('crypto');
34
var fs = require('fs');
45
var util = require('util'),
56
path = require('path'),
@@ -528,9 +529,10 @@ IncomingForm.prototype._initJSONencoded = function() {
528529
};
529530

530531
IncomingForm.prototype._uploadPath = function(filename) {
531-
var name = '';
532-
for (var i = 0; i < 32; i++) {
533-
name += Math.floor(Math.random() * 16).toString(16);
532+
var name = 'upload_';
533+
var buf = crypto.randomBytes(16);
534+
for (var i = 0; i < buf.length; ++i) {
535+
name += ('0' + buf[i].toString(16)).slice(-2);
534536
}
535537

536538
if (this.keepExtensions) {

0 commit comments

Comments
 (0)