File tree Expand file tree Collapse file tree 1 file changed +36
-4
lines changed Expand file tree Collapse file tree 1 file changed +36
-4
lines changed Original file line number Diff line number Diff line change @@ -32,11 +32,24 @@ function getLength(buf, p) {
32
32
return initial ;
33
33
}
34
34
var octetLen = initial & 0xf ;
35
+
36
+ // Indefinite length or overflow
37
+ if ( octetLen === 0 || octetLen > 4 ) {
38
+ return false ;
39
+ }
40
+
35
41
var val = 0 ;
36
42
for ( var i = 0 , off = p . place ; i < octetLen ; i ++ , off ++ ) {
37
43
val <<= 8 ;
38
44
val |= buf [ off ] ;
45
+ val >>>= 0 ;
39
46
}
47
+
48
+ // Leading zeroes
49
+ if ( val <= 0x7f ) {
50
+ return false ;
51
+ }
52
+
40
53
p . place = off ;
41
54
return val ;
42
55
}
@@ -60,28 +73,47 @@ Signature.prototype._importDER = function _importDER(data, enc) {
60
73
return false ;
61
74
}
62
75
var len = getLength ( data , p ) ;
76
+ if ( len === false ) {
77
+ return false ;
78
+ }
63
79
if ( ( len + p . place ) !== data . length ) {
64
80
return false ;
65
81
}
66
82
if ( data [ p . place ++ ] !== 0x02 ) {
67
83
return false ;
68
84
}
69
85
var rlen = getLength ( data , p ) ;
86
+ if ( rlen === false ) {
87
+ return false ;
88
+ }
70
89
var r = data . slice ( p . place , rlen + p . place ) ;
71
90
p . place += rlen ;
72
91
if ( data [ p . place ++ ] !== 0x02 ) {
73
92
return false ;
74
93
}
75
94
var slen = getLength ( data , p ) ;
95
+ if ( slen === false ) {
96
+ return false ;
97
+ }
76
98
if ( data . length !== slen + p . place ) {
77
99
return false ;
78
100
}
79
101
var s = data . slice ( p . place , slen + p . place ) ;
80
- if ( r [ 0 ] === 0 && ( r [ 1 ] & 0x80 ) ) {
81
- r = r . slice ( 1 ) ;
102
+ if ( r [ 0 ] === 0 ) {
103
+ if ( r [ 1 ] & 0x80 ) {
104
+ r = r . slice ( 1 ) ;
105
+ } else {
106
+ // Leading zeroes
107
+ return false ;
108
+ }
82
109
}
83
- if ( s [ 0 ] === 0 && ( s [ 1 ] & 0x80 ) ) {
84
- s = s . slice ( 1 ) ;
110
+ if ( s [ 0 ] === 0 ) {
111
+ if ( s [ 1 ] & 0x80 ) {
112
+ s = s . slice ( 1 ) ;
113
+ } else {
114
+ // Leading zeroes
115
+ return false ;
116
+ }
85
117
}
86
118
87
119
this . r = new BN ( r ) ;
You can’t perform that action at this time.
0 commit comments