@@ -161,29 +161,25 @@ public override int Read(byte[] buffer, int offset, int count)
161161 bytesToRead = Math . Min ( count - totalBytesRead , this . currentDataRemaining ) ;
162162 this . currentDataRemaining -= bytesToRead ;
163163 bytesRead = this . innerStream . Read ( buffer , offset , bytesToRead ) ;
164+ if ( bytesRead == 0 )
165+ {
166+ return totalBytesRead ;
167+ }
168+
164169 totalBytesRead += bytesRead ;
165170 }
166171
167172 return totalBytesRead ;
168173 }
169174
170175 /// <inheritdoc/>
171- public override long Seek ( long offset , SeekOrigin origin )
172- {
173- throw new NotSupportedException ( ) ;
174- }
176+ public override long Seek ( long offset , SeekOrigin origin ) => throw new NotSupportedException ( ) ;
175177
176178 /// <inheritdoc/>
177- public override void SetLength ( long value )
178- {
179- throw new NotSupportedException ( ) ;
180- }
179+ public override void SetLength ( long value ) => throw new NotSupportedException ( ) ;
181180
182181 /// <inheritdoc/>
183- public override void Write ( byte [ ] buffer , int offset , int count )
184- {
185- throw new NotSupportedException ( ) ;
186- }
182+ public override void Write ( byte [ ] buffer , int offset , int count ) => throw new NotSupportedException ( ) ;
187183
188184 /// <inheritdoc/>
189185 protected override void Dispose ( bool disposing )
@@ -245,22 +241,17 @@ private bool InitializeInflateStream(bool isCriticalChunk)
245241 // CINFO is not defined in this specification for CM not equal to 8.
246242 throw new ImageFormatException ( $ "Invalid window size for ZLIB header: cinfo={ cinfo } ") ;
247243 }
248- else
249- {
250- return false ;
251- }
244+
245+ return false ;
252246 }
253247 }
248+ else if ( isCriticalChunk )
249+ {
250+ throw new ImageFormatException ( $ "Bad method for ZLIB header: cmf={ cmf } ") ;
251+ }
254252 else
255253 {
256- if ( isCriticalChunk )
257- {
258- throw new ImageFormatException ( $ "Bad method for ZLIB header: cmf={ cmf } ") ;
259- }
260- else
261- {
262- return false ;
263- }
254+ return false ;
264255 }
265256
266257 // The preset dictionary.
@@ -269,7 +260,11 @@ private bool InitializeInflateStream(bool isCriticalChunk)
269260 {
270261 // We don't need this for inflate so simply skip by the next four bytes.
271262 // https://tools.ietf.org/html/rfc1950#page-6
272- this . innerStream . Read ( ChecksumBuffer , 0 , 4 ) ;
263+ if ( this . innerStream . Read ( ChecksumBuffer , 0 , 4 ) != 4 )
264+ {
265+ return false ;
266+ }
267+
273268 this . currentDataRemaining -= 4 ;
274269 }
275270
0 commit comments