Skip to content

Commit

Permalink
Fix for offset of colors in binary formats which begin image data wit…
Browse files Browse the repository at this point in the history
…h bytes that match whitespace characters
  • Loading branch information
chrdavis committed Oct 12, 2019
1 parent d48cec2 commit 5141262
Showing 1 changed file with 20 additions and 14 deletions.
34 changes: 20 additions & 14 deletions PIFShellExtensionsLib/PIFParser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -299,24 +299,30 @@ HRESULT CBaseImageParser::InitializeFromStream(_In_ IStream* pStream)
HRESULT hr = ReadImageHeaders();
if (SUCCEEDED(hr))
{
char chCurrent = ' ';
// Walk past any remaining whitespace
while (SUCCEEDED(hr) && IsWhitespace(chCurrent))
// Only read over whitespace for ASCII mode image formats
if ((m_imageType == PortableImageFormatType_PBMA) ||
(m_imageType == PortableImageFormatType_PGMA) ||
(m_imageType == PortableImageFormatType_PPMA))
{
hr = IStream_Read(pStream, (void*)&chCurrent, sizeof(char));
}
char chCurrent = ' ';
// Walk past any remaining whitespace
while (SUCCEEDED(hr) && IsWhitespace(chCurrent))
{
hr = IStream_Read(pStream, (void*)&chCurrent, sizeof(char));
}

if (SUCCEEDED(hr))
{
// Move back before the last read char
ULARGE_INTEGER uliCurrentSeek;
hr = pStream->Seek(c_liZero, STREAM_SEEK_CUR, &uliCurrentSeek);
if (SUCCEEDED(hr))
{
LARGE_INTEGER seekSet = { 0 };
seekSet.LowPart = uliCurrentSeek.LowPart - 1;
seekSet.HighPart = uliCurrentSeek.HighPart;
hr = pStream->Seek(seekSet, STREAM_SEEK_SET, nullptr);
// Move back before the last read char
ULARGE_INTEGER uliCurrentSeek;
hr = pStream->Seek(c_liZero, STREAM_SEEK_CUR, &uliCurrentSeek);
if (SUCCEEDED(hr))
{
LARGE_INTEGER seekSet = { 0 };
seekSet.LowPart = uliCurrentSeek.LowPart - 1;
seekSet.HighPart = uliCurrentSeek.HighPart;
hr = pStream->Seek(seekSet, STREAM_SEEK_SET, nullptr);
}
}
}
}
Expand Down

0 comments on commit 5141262

Please sign in to comment.