File tree Expand file tree Collapse file tree 1 file changed +23
-8
lines changed Expand file tree Collapse file tree 1 file changed +23
-8
lines changed Original file line number Diff line number Diff line change @@ -119,18 +119,33 @@ export default class JPEGDecoder {
119
119
let extra = 0 ;
120
120
if ( type === 0xDA ) {
121
121
// start of scan
122
- extra += 2 ;
122
+ if ( sock . rQwait ( "JPEG" , length - 2 + 2 , 4 ) ) {
123
+ return null ;
124
+ }
125
+
126
+ let len = sock . rQlen ( ) ;
127
+ let data = sock . rQpeekBytes ( len , false ) ;
128
+
123
129
while ( true ) {
124
- if ( sock . rQwait ( "JPEG" , length - 2 + extra , 4 ) ) {
130
+ let idx = data . indexOf ( 0xFF , length - 2 + extra ) ;
131
+ if ( idx === - 1 ) {
132
+ sock . rQwait ( "JPEG" , Infinity , 4 ) ;
125
133
return null ;
126
134
}
127
- let data = sock . rQpeekBytes ( length - 2 + extra , false ) ;
128
- if ( data . at ( - 2 ) === 0xFF && data . at ( - 1 ) !== 0x00 &&
129
- ! ( data . at ( - 1 ) >= 0xD0 && data . at ( - 1 ) <= 0xD7 ) ) {
130
- extra -= 2 ;
131
- break ;
135
+
136
+ if ( idx === len - 1 ) {
137
+ sock . rQwait ( "JPEG" , Infinity , 4 ) ;
138
+ return null ;
132
139
}
133
- extra ++ ;
140
+
141
+ if ( data . at ( idx + 1 ) === 0x00 ||
142
+ ( data . at ( idx + 1 ) >= 0xD0 && data . at ( idx + 1 ) <= 0xD7 ) ) {
143
+ extra = idx + 2 - ( length - 2 ) ;
144
+ continue ;
145
+ }
146
+
147
+ extra = idx - ( length - 2 ) ;
148
+ break ;
134
149
}
135
150
}
136
151
You can’t perform that action at this time.
0 commit comments