@@ -299,24 +299,30 @@ HRESULT CBaseImageParser::InitializeFromStream(_In_ IStream* pStream)
299
299
HRESULT hr = ReadImageHeaders ();
300
300
if (SUCCEEDED (hr))
301
301
{
302
- char chCurrent = ' ' ;
303
- // Walk past any remaining whitespace
304
- while (SUCCEEDED (hr) && IsWhitespace (chCurrent))
302
+ // Only read over whitespace for ASCII mode image formats
303
+ if ((m_imageType == PortableImageFormatType_PBMA) ||
304
+ (m_imageType == PortableImageFormatType_PGMA) ||
305
+ (m_imageType == PortableImageFormatType_PPMA))
305
306
{
306
- hr = IStream_Read (pStream, (void *)&chCurrent, sizeof (char ));
307
- }
307
+ char chCurrent = ' ' ;
308
+ // Walk past any remaining whitespace
309
+ while (SUCCEEDED (hr) && IsWhitespace (chCurrent))
310
+ {
311
+ hr = IStream_Read (pStream, (void *)&chCurrent, sizeof (char ));
312
+ }
308
313
309
- if (SUCCEEDED (hr))
310
- {
311
- // Move back before the last read char
312
- ULARGE_INTEGER uliCurrentSeek;
313
- hr = pStream->Seek (c_liZero, STREAM_SEEK_CUR, &uliCurrentSeek);
314
314
if (SUCCEEDED (hr))
315
315
{
316
- LARGE_INTEGER seekSet = { 0 };
317
- seekSet.LowPart = uliCurrentSeek.LowPart - 1 ;
318
- seekSet.HighPart = uliCurrentSeek.HighPart ;
319
- hr = pStream->Seek (seekSet, STREAM_SEEK_SET, nullptr );
316
+ // Move back before the last read char
317
+ ULARGE_INTEGER uliCurrentSeek;
318
+ hr = pStream->Seek (c_liZero, STREAM_SEEK_CUR, &uliCurrentSeek);
319
+ if (SUCCEEDED (hr))
320
+ {
321
+ LARGE_INTEGER seekSet = { 0 };
322
+ seekSet.LowPart = uliCurrentSeek.LowPart - 1 ;
323
+ seekSet.HighPart = uliCurrentSeek.HighPart ;
324
+ hr = pStream->Seek (seekSet, STREAM_SEEK_SET, nullptr );
325
+ }
320
326
}
321
327
}
322
328
}
0 commit comments