Skip to content

Commit 5141262

Browse files
committed
Fix for offset of colors in binary formats which begin image data with bytes that match whitespace characters
1 parent d48cec2 commit 5141262

File tree

1 file changed

+20
-14
lines changed

1 file changed

+20
-14
lines changed

PIFShellExtensionsLib/PIFParser.cpp

Lines changed: 20 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -299,24 +299,30 @@ HRESULT CBaseImageParser::InitializeFromStream(_In_ IStream* pStream)
299299
HRESULT hr = ReadImageHeaders();
300300
if (SUCCEEDED(hr))
301301
{
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))
305306
{
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+
}
308313

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);
314314
if (SUCCEEDED(hr))
315315
{
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+
}
320326
}
321327
}
322328
}

0 commit comments

Comments
 (0)